I want to enable rewrite logging so that I can debug a rewrite rule but adding the RewriteLog directives is causing a 500 error.
Version information:
Ubuntu 14.04
Server version: Apache/2.4.12 (Ubuntu)
Server built: Feb 4 2015 14:22:06
contents of .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 5
RewriteBase /
RewriteRule ^/wordpress/wp-content/(.*)$ /wp-content/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
In the error log I see:
/var/www/path.to/wordpress/.htaccess: Invalid command 'RewriteLog', perhaps misspelled or defined by a module not included in the server configuration
In addition to having forgotten that logging cannot be configured in
.htaccess
files, this also turned out to be an Apache version issue. The RewriteLog directive has been replaced in newer versions and adding the following to the Virtualhost configuration enabled the rewrite log for me:From the manual:
Those familiar with earlier versions of mod_rewrite will no doubt be looking for the RewriteLog and RewriteLogLevel directives. This functionality has been completely replaced by the new per-module logging configuration mentioned above.
To filter out these messages in the error log you can do something like:
I can't help repeating myself:
Most people who use .htaccess and ask about it on ServerFault should not be using .htaccess in the first place as that is an end-user solution never intended for administrators:
Apparently most people who publish their configurations appear to be cargo cult programmers keen on copying .htaccess files blindly without understanding the reasons.
Your problem is a prime example: the
RewriteLog
directive is only valid in the context of a server config or the virtual host...That means it is not allowed in a
.htaccess
file!