If you are an Apache server administrator or a developer testing out your .htaccess file with rewrite rules in it then you should be aware of mechanisms on how to debug rewrite rule in Apache. Rewrite rules can be quite tricky and trying to debug rewrite rule in Apache requires access to Apache server directories. This is so because you might need to modify some of the configuration files to allow for writing the debug information relevant to rewrite rules being used.

There are two ways to debug rewrite rule in Apache based on the permissions set up by your administrator. You can enable logging of any debug information for rewrite rule via .htacess or httpd.conf files.

Debug rewrite rule in apache

Debug rewrite rule in Apache using .htaccess

This is the easiest option as there is no need to access any Apache directories or configuration files for this option. Here, all that needs to be done is to add following lines for code in the .htaccess file that you need to debug.

RewriteLogLevel 9
RewriteLog "/tmp/rewrite.log"

The code here is self explanatory. All it is saying is that any logs relating to rewrite rules should be written to /tmp/rewrite.log file and that debug level is set to 9. The default level is 0 which means no logging, while 9 or more means that all actions are to be logged. To disable the logging of rewrite rules just set Level to 0. This disables all rewrite action logs.

Debug rewrite rule in Apache using httpd.conf

The above option could however fail with following in error.log located at /var/log/apache2 :

.htaccess: RewriteLog not allowed here

The error “Rewrite Log not allowed here” suggests that specifying Rewiteloglevel and directory for logging is not supported in .htaccess file. Therefore, in such a scenario, the solution is to place the lines of code from above into httpd.conf file located at /etc/apache2 rather than .htaccess.


Tags: