为什么在 .htaccess 中启用重写日志不起作用?

cod*_*boy 12 mod-rewrite apache-2.4

我想启用重写日志记录,以便我可以调试重写规则,但添加 RewriteLog 指令会导致 500 错误。

版本信息:

Ubuntu 14.04

Server version: Apache/2.4.12 (Ubuntu)
Server built:   Feb  4 2015 14:22:06
Run Code Online (Sandbox Code Playgroud)

的内容 .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>
Run Code Online (Sandbox Code Playgroud)

在错误日志中我看到:

/var/www/path.to/wordpress/.htaccess: Invalid command 'RewriteLog', perhaps misspelled or defined by a module not included in the server configuration
Run Code Online (Sandbox Code Playgroud)

cod*_*boy 18

除了忘记不能在.htaccess文件中配置日志记录之外,这也被证明是 Apache 版本问题。RewriteLog 指令已在较新版本中被替换,并将以下内容添加到 Virtualhost 配置中,为我启用了重写日志:

LogLevel alert rewrite:trace3 (can be increased to trace8)
Run Code Online (Sandbox Code Playgroud)

从手册:

那些熟悉 mod_rewrite 早期版本的人无疑会寻找 RewriteLog 和 RewriteLogLevel 指令。此功能已被上述新的每模块日志记录配置完全取代。

要在错误日志中过滤掉这些消息,您可以执行以下操作:

tail -f error_log|fgrep '[rewrite:'
Run Code Online (Sandbox Code Playgroud)