I have a web application, the front end is HTML & JavaScript/jQuery and The back is PHP.
It was using ugly URL's like so, host/app/Page.php?userid=1.... Ugly! So with a little MOD_REWRITE it will now serve the urls as url/page/1/
RewriteRule ^page/([0-9]+)/?$ host/app/page.php?userid=$1 [NC,L]
Next it originally did simple jQuery GET request to the PHP files to get the dynamic data.
var params = A JS function to get all paramters after the ? in URL
var userid = params.id;
$.getJSON('host/app/page_code.php',{'userid':userid}, function(data) {
var blah = data.blah;
});
Now after using MOD_REWRITE I now have no nice way of getting the front end to the parameters, only in a page/1 format. Looping though and getting each parameter between the slashes just doesn't feel like the right way to do it.
So I hit Google and it seems that sending the parameters from MOD_REWRITE seems like the way to do it. So my questions are, how is this possible, how is it done?
How do I get the parameters from the URL with MOD_REWRITE, send those to the PHP back-end, then return a response to the front end with JSON?
edit: The problem I have is I need to pass Parameters from JS to a PHP back end then get a response. I originally got these parameters from the URL with JS, then passed them into the GET request, I would then get a response from the PHP depending on the Parameter sent. However now I have used mod_rewrite on the URL I can not see the parameters on the front end to catch in the traditional ?a=b&c=d format. it now looks like /b/d To get these in JS I can only do this by looping through and getting each parameter between the slashes. Doesn't seem right to do it like this. I need to actually some how get the parameters to the PHP code in a separate page from the front end. Then pass it back to the front end with the response from the PHP code so I have lets say the users id. I don't want any php in the front end file as to keep it all separated. There must be a way to get the parameters from the url to the PHP code in a different file, then send back a response to the front end HTML&JS with the usersid. I'm new to this whole MOD_REWRITE for clean urls, and it's confusing the hell out of me!