I need URL parameter from a rewritten URL (htacces).
I have this function but it returns NULL:
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results===null){
return null;
}
else{
return results[1] || 0;
}
};
And this is how I'm calling for the parameter:
var value = $.urlParam('profile');
I need to get "1" from "page.php/profile/1"
Thanks in advance!
With @weigreen's help I've modified my RegExp:
var results = new RegExp('[/]' + name + '/([^#]*)').exec(window.location.href);
EDIT:
For multiple parameters (/profile/1/page/2) this was a better solution:
var results = new RegExp('[/]' + name + '/([a-z0-9]+)').exec(window.location.href);