问题
I am trying to troubleshoot mod_rewrite on Apache2.2.15 operating on Centos 6.5. My httpd.conf
file is as follows:
<VirtualHost *:80>
ServerName somesite.com
DocumentRoot /var/www/somesite/html
<Directory "/var/www/somesite/html">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 3
</IfModule>
</Directory>
</VirtualHost>
I keep on getting the following error where line 1044 corresponds to RewriteLog /var/log/httpd/rewrite.log
.
[root@devserver httpd]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: Syntax error on line 1044 of /etc/httpd/conf/httpd.conf:
RewriteLog not allowed here
[FAILED]
[root@devserver httpd]#
I can add RewriteLog /var/log/httpd/rewrite.log
to the main section (not virtual host) of httpd.conf, but nothing gets logged from the virtual host.
How do I log mod_rewrite transactions?
回答1:
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
RewriteLog needs to have a context of server config or virtual host. Try this instead:
<VirtualHost *:80>
<IfModule mod_rewrite.c>
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 3
</IfModule>
ServerName somesite.com
DocumentRoot /var/www/somesite/html
<Directory "/var/www/somesite/html">
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
</Directory>
</VirtualHost>
来源:https://stackoverflow.com/questions/23294134/logging-mod-rewrite-on-apache-2-2