Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 2.4根/匹配项的重写规则,但根据重写调试日志被忽略(索引文件的子请求仍在继续)_Apache_Rewrite - Fatal编程技术网

Apache 2.4根/匹配项的重写规则,但根据重写调试日志被忽略(索引文件的子请求仍在继续)

Apache 2.4根/匹配项的重写规则,但根据重写调试日志被忽略(索引文件的子请求仍在继续),apache,rewrite,Apache,Rewrite,编辑:我向Apache报告了这一点,它确实是一个bug,已在2.4.9中修复,请参阅。。。对于Ubuntu,有一个更新的PPA。对于那些无法升级或不想编译的用户,我在下面发布了一个解决方案 这已经让我发疯了。Ubuntu 14.04上的Apache 2.4.7。重写规则很简单: RewriteCond %{REQUEST_URI} ^/?$ RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [L] 基本

编辑:我向Apache报告了这一点,它确实是一个bug,已在2.4.9中修复,请参阅。。。对于Ubuntu,有一个更新的PPA。对于那些无法升级或不想编译的用户,我在下面发布了一个解决方案

这已经让我发疯了。Ubuntu 14.04上的Apache 2.4.7。重写规则很简单:

RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [L]
基本上,我想为/提供一个.html文件。.html文件存在,如果直接请求,可以正常提供。正如您在下面的调试日志中所看到的(
LogLevel alert rewrite:trace6
,在服务器配置中),cond on/确实匹配(
initial
),但Apache继续(
subreq
)并未能匹配/index.html、/index.cgi、/index.pl和/index.php,最后提供/index.php

这是预料不到的<代码>[L]应该阻止Apache在找到匹配项后继续

我可以确认Apache 2.2中不存在此问题。这看起来像Apache2.4中的一个bug。。。还是我遗漏了什么

另外,另一件令人沮丧的事情是,这似乎只是/的问题。同样的规则只适用于子目录(即,
RewriteCond%{REQUEST_URI}^/subdr/?$
)也可以按照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
有什么线索吗?

目前,我的(丑陋的)解决方案是:

RewriteCond %{REQUEST_URI} ^(/index.\w+|/)?$
RewriteRule ^ /web/wp-content/cache/page_enhanced/HOSTNAME/_index.html [L]
换句话说,我将匹配所有可能的/index.*以及/。前者应该是不必要的,在我的情况下,它使我的设置复杂化,因为index.php应该匹配其他规则,所以我也需要解决这个问题

请注意,此错误(?)仅发生在/。子目录的相同规则也适用,即:

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