The error message you're encountering (Invalid command 'RewriteLog'
) occurs because these directives were removed in Apache 2.4+. The logging functionality has been integrated into the core error log using the LogLevel
directive instead.
For Apache 2.4+, use this configuration in either your virtual host or .htaccess:
RewriteEngine On
RewriteBase /
# For Apache 2.4+ debugging
LogLevel alert rewrite:trace5
RewriteRule ^/wordpress/wp-content/(.*)$ /wp-content/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The rewrite traces will appear in your main Apache error log (typically /var/log/apache2/error.log
). To monitor logs in real-time:
tail -f /var/log/apache2/error.log | grep "rewrite:trace"
Even with correct configuration, you might need to:
sudo chmod 644 /var/log/apache2/error.log
sudo service apache2 restart
If you don't have access to server logs, insert debugging rules:
RewriteRule ^(.*)$ - [E=DEBUG_PATH:%{REQUEST_URI},L]
Header set X-Rewrite-Debug "%{DEBUG_PATH}e" env=DEBUG_PATH
A sample trace entry looks like:
[rewrite:trace3] applying pattern '^index\.php$' to uri 'test.html'
[rewrite:trace4] RewriteCond: input='/var/www/test.html' pattern='!-f' => matched
The error message you're seeing (Invalid command 'RewriteLog'
) occurs because these directives were removed in Apache 2.4. The traditional debugging approach using RewriteLog
and RewriteLogLevel
no longer works in current Apache versions. Here's what changed:
# Old Apache 2.2 syntax (deprecated):
RewriteLog "/path/to/logfile"
RewriteLogLevel 3
# Apache 2.4+ replacement:
LogLevel alert rewrite:trace6
For Apache 2.4+, you'll need to configure rewrite logging through the main Apache configuration rather than .htaccess:
# In your Apache config (httpd.conf or virtual host file)
<VirtualHost *:80>
ServerName example.com
LogLevel debug
ErrorLog /var/log/apache2/example_error.log
CustomLog /var/log/apache2/example_access.log combined
# Specific rewrite logging (levels 1-8, 8 being most verbose)
LogLevel alert rewrite:trace6
</VirtualHost>
Here's how to properly debug your WordPress rewrite rules:
- Modify your main Apache config (not .htaccess)
- Restart Apache:
sudo service apache2 restart
- Make test requests
- Check error logs:
tail -f /var/log/apache2/error.log
When working correctly, you'll see detailed rewrite processing:
[rewrite:trace3] applying pattern '^/wordpress/wp-content/(.*)$' to uri '/wordpress/wp-content/themes/style.css'
[rewrite:trace2] rewrite '/wordpress/wp-content/themes/style.css' -> '/wp-content/themes/style.css'
[rewrite:trace1] internal redirect with /wp-content/themes/style.css [INTERNAL REDIRECT]
If you can't modify server configs, try these alternatives:
# Add environment variable logging
RewriteRule ^ - [E=DEBUG_MSG:%{REQUEST_URI},L]
Header set X-Rewrite-Debug "%{DEBUG_MSG}e" env=DEBUG_MSG
# Or use PHP to log rewrite behavior
<?php
file_put_contents('rewrite_debug.log', $_SERVER['REQUEST_URI']."\n", FILE_APPEND);
?>
Ensure your log directory has proper permissions:
sudo chown www-data:www-data /var/log/apache2/
sudo chmod 755 /var/log/apache2/