11

在 apache2 中与 mod_rewrite 作斗争。问题是这些指令在放入 httpd.conf 时会被忽略。

如果我AllowOverride All在sites-available/default 中设置并将指令添加到.htaccess 它可以工作并且每个请求都会在mod_rewrite.log 中弹出。

但是当我删除 .htaccess 并将AllowOverride All指令添加到 httpd.conf 时,它被忽略了。

Httpd.conf 看起来像这样:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteLog "/var/log/apache2/mod_rewrite.log"
    RewriteLogLevel 4 
    RewriteRule ^/.* http://www.google.com                                     
</IfModule>

(刚选google调试)

Phpinfo() 在加载的模块中显示 mod_rewrite,rewrite.load 在 /mods-enabled 处符号链接到 mods-available,即它确实存在。此外,当我删除 mod_rewrite.log 它是在服务器启动时创建的,IMO 指示 httpd.conf 已读取并且 mod_rewrite.c 存在。但是 mod_rewrite.log 保持空白,这表明没有请求发送到 mod_rewrite。此外,将废话放入 httpd.conf 服务器将无法启动并引发错误。

我错过了什么?有没有像AllowOverride我必须为主要配置文件设置的东西?

我已经玩过/as .htaccess 使用相对路径而 httpd.conf 没有。我也尝试设置<Directory>标签,这对我来说没有意义,但仍然尝试看看它是否改变了任何东西......帮助?!


我自己想通了,但万一有人遇到同样的问题:

httpd.conf 中设置的“全局”重写规则必须包含在每个虚拟主机中,使用

<VitualHost *:80>
    RewriteEngine on
    RewriteOptions Inherit
</VirtualHost>

否则它们将无法在 VHosts 中工作。此外,父规则在子规则之后应用。

4

0 回答 0