阿帕奇2.4重写规则根/的比赛,但被忽略(subreq索引文件仍然继续),按照重写调试日志(Apac

2019-10-19 23:15发布

编辑 :我报这Apache和它确实是一个错误,定格在2.4.9,看到这里 ...对于Ubuntu的,有一个更新的PPA 这里 。 对于那些谁无法升级或不想去编译,我下面贴一个解决办法

这已经是我发疯。 阿帕奇2.4.7在Ubuntu 14.04。 重写规则很简单:

RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [L]

基本上,我想以服务为/ .html文件。 .html文件存在,如果直接请供应正常。 正如你可以在下面的调试日志中看到( LogLevel alert rewrite:trace6在服务器的conf),上/中COND不匹配( initial ),但随后的Apache收益( subreq )和匹配失败/index.html,/索引。 CGI,/index.pl和的index.php,最后提供的index.php。

这不是预期。 [L]应该防止Apache继续一旦发现匹配。

我可以证实,这个问题不存在于Apache 2.2存在。 这看起来像阿帕奇2.4的错误......还是我失去了一些东西?

此外,另一个令人沮丧的是,这似乎是只对/一个问题。 同样的规则,但对于一个子目录(即RewriteCond %{REQUEST_URI} ^/subdir/?$ )预期在2.4太工作。

重写调试日志:

# grep rewrite: /var/log/apache2/error.log
[Sat Apr 19 20:40:14.581933 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabc90a0/initial] [perdir /var/www/HOSTNAME/] strip per-dir prefix: /var/www/HOSTNAME/ -> 
[Sat Apr 19 20:40:14.581957 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabc90a0/initial] [perdir /var/www/HOSTNAME/] applying pattern '.*' to uri ''
[Sat Apr 19 20:40:14.581963 2014] [rewrite:trace4] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabc90a0/initial] [perdir /var/www/HOSTNAME/] RewriteCond: input='/' pattern='^/?$' => matched
[Sat Apr 19 20:40:14.581966 2014] [rewrite:trace2] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabc90a0/initial] [perdir /var/www/HOSTNAME/] rewrite '' -> '/web/wp-content/cache/page_enhanced/HOSTNAME/_index.html'
[Sat Apr 19 20:40:14.581969 2014] [rewrite:trace1] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabc90a0/initial] [perdir /var/www/HOSTNAME/] internal redirect with /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [INTERNAL REDIRECT]
[Sat Apr 19 20:40:14.582407 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] strip per-dir prefix: /var/www/HOSTNAME/index.html -> index.html
[Sat Apr 19 20:40:14.582414 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] applying pattern '.*' to uri 'index.html'
[Sat Apr 19 20:40:14.582418 2014] [rewrite:trace4] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] RewriteCond: input='/index.html' pattern='^/?$' => not-matched
[Sat Apr 19 20:40:14.582420 2014] [rewrite:trace1] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] pass through /var/www/HOSTNAME/index.html
[Sat Apr 19 20:40:14.582767 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] strip per-dir prefix: /var/www/HOSTNAME/index.cgi -> index.cgi
[Sat Apr 19 20:40:14.582772 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] applying pattern '.*' to uri 'index.cgi'
[Sat Apr 19 20:40:14.582775 2014] [rewrite:trace4] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] RewriteCond: input='/index.cgi' pattern='^/?$' => not-matched
[Sat Apr 19 20:40:14.582777 2014] [rewrite:trace1] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] pass through /var/www/HOSTNAME/index.cgi
[Sat Apr 19 20:40:14.583131 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] strip per-dir prefix: /var/www/HOSTNAME/index.pl -> index.pl
[Sat Apr 19 20:40:14.583136 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] applying pattern '.*' to uri 'index.pl'
[Sat Apr 19 20:40:14.583143 2014] [rewrite:trace4] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] RewriteCond: input='/index.pl' pattern='^/?$' => not-matched
[Sat Apr 19 20:40:14.583146 2014] [rewrite:trace1] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] pass through /var/www/HOSTNAME/index.pl
[Sat Apr 19 20:40:14.583375 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] strip per-dir prefix: /var/www/HOSTNAME/index.php -> index.php
[Sat Apr 19 20:40:14.583380 2014] [rewrite:trace3] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] applying pattern '.*' to uri 'index.php'
[Sat Apr 19 20:40:14.583383 2014] [rewrite:trace4] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] RewriteCond: input='/index.php' pattern='^/?$' => not-matched
[Sat Apr 19 20:40:14.583386 2014] [rewrite:trace1] [pid 20459] mod_rewrite.c(468): [client 192.168.198.1:14715] 192.168.198.1 - - [HOSTNAME/sid#7fd7ed4f0528][rid#7fd7dabcd0a0/subreq] [perdir /var/www/HOSTNAME/] pass through /var/www/HOSTNAME/index.php

任何线索?

Answer 1:

现在,我的(丑陋的)解决方法解决方法是:

RewriteCond %{REQUEST_URI} ^(/index.\w+|/)?$
RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [L]

换句话说,我匹配对一切可能发生/index.*以及/。 前者不应该是必要的,在我的情况下,我的设置复杂的,所以我需要解决,太多的index.php应与其他规则...

请注意,这个bug(?)仅发生于/。 子目录同样的规则做工精细,即:

RewriteCond %{REQUEST_URI} ^/subdir/?$
RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/subdir/_index.html [L]

工作得很好...



文章来源: Apache 2.4 Rewrite rule for root / matches but is ignored (subreq for index files still proceed) as per rewrite debug logs