Forum Moderators: phranque
Upon using it on a url like this:
[localhost...]
The pageName variable when reached by index.php comes out as "index" instead of the requested "home".
Can anyone shed some light why when passing home.php into the pageName variable it comes out as "index" on the other end?
Running Apache 2.2 on windows.
The first time through, the pageName variable is assigned the value "home" and the URL is rewritten to "index.php". But the rule runs again, because after any rule is invoked in an .htaccess context, mod_rewrite processing is re-started. So, the second time through, the "php page name" is now index.php, and this is populated into the query string pageName value. Then the rule runs again, and repeats until the server gives up.
Using [QSA], you'll likely find that your actual query string was
"pageName=home&pageName=index&pageName=index&pageName=index&pageName=index&pageName=index&pageName=index&pageName=index&pageName=index&pageName=index"
because QSA (Query String Append) tells mod_rewrite to append the new query parameters to the existing ones, rather than replacing the entire query string. (I show ten pageName= parameters, assuming that your server redirection limit is set to ten. You may see more or less depending on your actual limit setting, but you'll see only one set to "home" and the rest set to "index.")
The correct solution is to explicitly prevent recursion:
RewriteCond $1 !^index$
RewriteRule ^([^.]+)\.php$ index.php?pageName=$1 [L]