Forum Moderators: phranque
RewriteEngine on
RewriteRule ^handler\.php$ - [L]
RewriteRule ^(.+)$ /Redirect/handler.php?cat=$1&%{QUERY_STRING} [L]
This works for the following situations:
/Redirect/test1/test2.html -> /Redirect/handler.php?cat=test1/test2.html
/Redirect/test1/test2.html?a=b&c=d -> /Redirect/handler.php?cat=test1/test2.html&a=b&c=d
/Redirect/test1?a=b&c=d -> /Redirect/handler.php?cat=test1&a=b&c=d
Unfortunately, it breaks on this scenario:
/Redirect/?a=b&c=d
Apparently, queries based on the root directory for the redirect don't map over correctly.
Can anyone clue-by-four me with the last bit of the rule I'm missing?
Thanks.
RewriteRule ^(.+)$ /Redirect/handler.php?cat=$1&%{QUERY_STRING} [L]
I'd suggest:
RewriteRule ^(.*)$ /Redirect/handler.php?cat=$1 [QSA,L]
One more stupid programmer question. What is the "QSL" param for?
Thanks for the help with this.
OK, these rules ended up being much shorter than I would have expected.
RewriteEngine on
RewriteRule ^handler\.php$ - [L]
RewriteRule ^(.*)$ handler.php?cat=$1 [L,QSA]
Note that even the "/Redirect" wasn't necessary being that handler.php is in the Redirect directory. Except for the slightly odd behavior when no trailing slash is present on "/Redirect" everything looks great. Fortunately, that is a pretty easy test to put in the code.
Thanks very much for the help.