How to debug Apache mod_rewrite

Solution 1:

One trick is to turn on the rewrite log. To turn it on, try this line in your Apache HTTP Server main configuration or current virtual host file (not in .htaccess):

LogLevel alert rewrite:trace6

Before Apache httpd 2.4 mod_rewrite, such a per-module logging configuration did not exist yet. Instead you could use the following logging settings:

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3

Solution 2:

The RewriteLog directive as mentioned by Ben is not available any more in Apache 2.4.

You need to use the LogLevel directive instead. E.g.,

LogLevel alert rewrite:trace6

See Apache Module mod_rewrite, Logging.

Solution 3:

For basic URL resolution, use a command line fetcher like wget or curl to do the testing, rather than a manual browser. Then you don't have to clear any cache; just up arrow and press Enter in a shell to rerun your test fetches.

Solution 4:

There's the htaccess tester.

It shows which conditions were tested for a certain URL, which ones met the criteria and which rules got executed.

It seems to have some glitches, though.