我知道很多人都发布过有关此错误的帖子,但是我仍然无法解决它。所以这就是我用它开始新帖子的原因。
正如标题所述,我在访问网站中的页面时遇到重定向循环。
这是我的重写配置。
RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
RewriteRule (.*)$ /test/$1 [R]
那么,我该如何解决这个重定向错误?
[Fri May 16 12:18:20.345204 2014] [rewrite:trace3] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] applying pattern '(.*)$' to uri '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test/ /store.do', referer: http://example.com/test/store.do
[Fri May 16 12:18:20.345213 2014] [rewrite:trace4] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] RewriteCond: input='http://example.com/test/store.do' pattern='^http://example\\.com/test/store\\.do' [NC] => matched, referer: http://example.com/test/store.do
[Fri May 16 12:18:20.345218 2014] [rewrite:trace2] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] rewrite '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//whatshot_v3/hahah/store.do' -> '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store.do', referer: http://example.com/test/store.do
[Fri May 16 12:18:20.345233 2014] [rewrite:trace2] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] explicitly forcing redirect with http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test/ /store.do, referer: http://example.com/test/store.do
[Fri May 16 12:18:20.345239 2014] [rewrite:trace1] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] escaping http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store.do for redirect, referer: http://example.com/test/store.do
[Fri May 16 12:18:20.345245 2014] [rewrite:trace1] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] redirect to http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store/store.do [REDIRECT/302], referer: http://example.com/test/store.do
这是我的日志文件。
谢谢。
答案1
如果可能的话,最好的解决方案可能是将对其他资源的引用更改为包含它,/test/
而不是在 mod_rewrite 中对其进行破解。
但是,这应该可行:
RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
RewriteRule ^/test - [L]
RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
RewriteRule ^/(.*)$ /test/$1 [L]
请注意,它不是重定向,因为没有理由让客户端为每个资源发送额外的请求,尽管这仍然有效。
答案2
尝试调试 RewriteRules 时,最好的办法是打开重写日志并提高 rewriteloglevel。这将显示传入的请求、每条规则的通过/失败情况,以及当请求与规则匹配时它对请求执行的操作。
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
RewriteLogLevel 3
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel
请记住在完成后禁用此功能,因为它会对性能造成影响,尤其是在 3 及以上版本。