Logging mod_rewrite on Apache 2.2

淺唱寂寞╮ 提交于 2019-12-12 01:32:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!