Debugging a mod_rewrite rule
apache, htaccess
Debugging a mod_rewrite rule can be a real pain. Often times, you want rewrite your url to something more understandable and elegant, but you can't quite get the regular expression down. Since by default, the browser is not sent a redirect, you can't check the address bar of your browser to see if the regular expression is working as you hoped. This turns debugging into guess and checking. To remedy this situation, you can add a redirect flag to the end of the rule and then the browser will be instructed to reload the page. This will let you see what effect, if any, the rewrite had on the url.
RewriteRule ^products([0-9][0-9])/$ productinfo.php?prodID=$1 [R]
...
It's the [R] at the end there that will help you out.
This is by no means an exhaustive list of what to do when your .htaccess rewrite rule isn't working, but it's one more option that's good to have in your toolbag.
Comments powered by Disqus