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.
To set up a debugging log for mod_rewrite, you need to add them to your httpd.conf to the appropriate VirtualHost section.
- Add following rules to your httpd.conf
<IfModule mod_rewrite.c> RewriteLog "/var/log/httpd/rewrite.log" RewriteLogLevel 3 </IfModule>
to the appropriate VirtualHost section.
- Restart Apache by command in your shell (as root)
apachectl graceful
Note: You’re not going to be able to turn above rules with shared hosting, they can’t be used in .htaccess by default. But you could ask your server-administrator to set AllowOverride to “All” instead “None”. And you will available to add above rules to .htaccess.
There a trick that’s helps debug mod_rewrite on shared hosting even AllowOverride is “None”.
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.
Add following rules to .htaccess:
RewriteCond %{QUERY_STRING} !vardump
RewriteRule (.*) http://www.your_website.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST} [R=301,L,QSA]
to dump, for example, the THE_REQUEST and HTTP_HOST into request variables.
The R=301 does a 301 redirect instead of a rewrite – this is key. A redirect sends information back to the browser but a rewrite happens all inside the server.
