At the risk of turning this into an Apache fan blog, I have to mention the handy directive I found today. Many webmasters run in to mod_rewrite at one time or another and every one of them will have at least a little trouble with it. I just came across the RewriteLog Directive and corresponding RewriteLogLevel Directive. You're not going to be able to turn these on with shared hosting, they can't be used in .htaccess. To set up a debugging log for mod_rewrite, you need to add them to your httpd.conf somewhere. In my case I'm working on a server at home so I added
to the appropriate VirtualHost section. After that I restarted apache and now every request generates a bunch of lines in the log file. Every request that a rule could possibly apply to makes some debug info, so don't forget to remove (or comment out) those lines in the conf file and restart Apache when you're done debugging.
While I'm on the subject, here's the other method that's helped me debug mod_rewrite on shared hosting. I originally found the tip from jdMorgan on Webmasterworld and tweaked it when I was doing a multisite Drupal install (here's my post from back then). Basically what you do is dump some of the info that mod_rewrite is using back out into the headers then use the Firebug or LiveHTTP Headers extensions in Firefox to watch the headers and read your debug info.
In .htaccess use the condition and rule:
You'll have to tweak the example to suit your needs but you can set it to dump anything that mod_rewrite can see in .htaccess.
That's very useful. I just love Apache!
Thanks so much for posting this. I am debugging a mod_rewrite problem but had forgotten this trick. (Probably a suppressed memory!) It\'s strange the mod_rewrite docs don\'t mention it more prominently.
Wordpress must have auto-wrapped a link tag. I had to change it to something like:
RewriteCond %{QUERY_STRING} !vardump
RewriteRule (.*) /$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST} [R=301,L,QSA]
Not sure if you meant Firefox's LiveHeaders is need for the above, but to my surprise it wasn't. It rewrites to the url to something like:
yourdomain.com/vardump&thereq='output here'&reqhost='output here 2'
This helped me greatly! Thanks!