Apache重写 - 代理添加了额外的index.php

时间:2015-08-11 14:39:27

标签: apache .htaccess mod-rewrite url-rewriting

我正在尝试最近两天调试这个问题而且我的智慧结束了。

当查询字符串有http://localhost:xxx时,我正在尝试将请求路由到escaped_fragment。重写规则是匹配的,并且它被路由到代理,但我不确定为什么重新启动重写规则并且index.php被添加到请求URL。

请求网址:

http://local.xxx.in/?_escaped_fragment

我的.htaccess文件

RewriteEngine On

RewriteCond %{HTTP_HOST} ^woohoo.in
RewriteRule (.*) http://www.woohoo.in/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_

# Only proxy the request to Phantomjs if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://localhost:32768/$2 [NC,P,END,QSA,T=text/html]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} \.html$
RewriteRule ^(.*)\.html$ $1 [L,R]


RewriteRule ^inc/.*$ index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php

请求的RewriteLog

[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] strip per-dir prefix: /home/robert/work/projects/gb/giftbigui/ ->
[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] applying pattern '(.*)' to uri ''
[rewrite:trace4] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] RewriteCond: input='local.woohoo.in' pattern='^woohoo.in' => not-matched
[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] strip per-dir prefix: /home/robert/work/projects/gb/giftbigui/ ->
[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] applying pattern '^(?!.*?(\\.js|\\.css|\\.xml|\\.less|\\.png|\\.jpg|\\.jpeg|\\.gif|\\.pdf|\\.doc|\\.txt|\\.ico|\\.rss|\\.zip|\\.mp3|\\.rar|\\.exe|\\.wmv|\\.doc|\\.avi|\\.ppt|\\.mpg|\\.mpeg|\\.tif|\\.wav|\\.mov|\\.psd|\\.ai|\\.xls|\\.mp4|\\.m4a|\\.swf|\\.dat|\\.dmg|\\.iso|\\.flv|\\.m4v|\\.torrent|\\.ttf|\\.woff))(.*)' to uri ''
[rewrite:trace4] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] RewriteCond: input='curl/7.35.0' pattern='baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\\ link\\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator' [NC] => not-matched
[rewrite:trace4] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] RewriteCond: input='_escaped_fragment_=1' pattern='_escaped_fragment_' => matched
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] rewrite '' -> 'http://localhost:32768/'
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] escaped URI in per-dir context for proxy, http://localhost:32768/ -> http://localhost:32768/
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] forcing proxy-throughput with http://localhost:32768/
[rewrite:trace1] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#18596f0/initial] [perdir /home/robert/work/projects/gb/giftbigui/] go-ahead with proxy request proxy:http://localhost:32768/?_escaped_fragment_=1 [OK]
[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] strip per-dir prefix: /home/robert/work/projects/gb/giftbigui/index.php -> index.php
[rewrite:trace3] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] applying pattern '^(?!.*?(\\.js|\\.css|\\.xml|\\.less|\\.png|\\.jpg|\\.jpeg|\\.gif|\\.pdf|\\.doc|\\.txt|\\.ico|\\.rss|\\.zip|\\.mp3|\\.rar|\\.exe|\\.wmv|\\.doc|\\.avi|\\.ppt|\\.mpg|\\.mpeg|\\.tif|\\.wav|\\.mov|\\.psd|\\.ai|\\.xls|\\.mp4|\\.m4a|\\.swf|\\.dat|\\.dmg|\\.iso|\\.flv|\\.m4v|\\.torrent|\\.ttf|\\.woff))(.*)' to uri 'index.php'
[rewrite:trace4] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] RewriteCond: input='curl/7.35.0' pattern='baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\\ link\\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator' [NC] => not-matched
[rewrite:trace4] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] RewriteCond: input='_escaped_fragment_=1' pattern='_escaped_fragment_' => matched
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] rewrite 'index.php' -> 'http://localhost:32768/index.php'
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] escaped URI in per-dir context for proxy, http://localhost:32768/index.php -> http://localhost:32768/index.php
[rewrite:trace2] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] forcing proxy-throughput with http://localhost:32768/index.php
[rewrite:trace1] [pid 8971] mod_rewrite.c(475): [client 127.0.0.1:57756] 127.0.0.1 - - [local.woohoo.in/sid#14b31a0][rid#1865e00/subreq] [perdir /home/robert/work/projects/gb/giftbigui/] go-ahead with proxy request proxy:http://localhost:32768/index.php?_escaped_fragment_=1 [OK]

----------------- ---- EDIT

我的apache版本是2.4.12,我发现这在2.2.x中运行良好

1 个答案:

答案 0 :(得分:1)

尝试过DirectoryCheckHandler?不幸的是,需要在PR53929中触发更新。我不记得为什么这个“修复”默认不启用 - 也许担心2.4.8为时已晚,无法改变行为。