由于可能的配置错误,请求超出了10个内部重定向的限制。

时间:2015-05-10 14:45:02

标签: mod-rewrite

mod_rewrite规则抛出此错误

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

这是我的规则

RewriteEngine On
# Removes index.php
RewriteBase /
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*families-of-schools/start/(.+?)$ /index.php/toolkit/families-of-schools/start?school=$1 [L]
RewriteRule ^(.*)$ /index.php/$1 [QSA,NC,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

问题发生在

RewriteRule .*families-of-schools/start/(.+?)$ /index.php/toolkit/families-of-schools/start?school=$1 [L]

我读到了很多关于某个循环的说法,但我没有看到循环可以在这里。手指上有人可以解释一下吗?网址是

/toolkit/families-of-schools/start/ash-green-school-cv7-9ah

1 个答案:

答案 0 :(得分:0)

我怀疑问题规则是你指出的规则。在重写一次之后,假设index.php确实存在,由于第二个条件(!-f),它不应该再次匹配。然而,第二条规则会将index.php添加到网址直到永恒。

为防止将来出现问题,您还应将重定向规则移至所有其他规则之上。我建议只使用临时重定向,直到.htaccess中的所有内容都经过测试并按预期工作。永久重定向被缓存,如果你在某处犯了错误,那么在你经历清除缓存的痛苦过程之前,你所做的任何更改都是不可见的。

RewriteEngine On
RewriteBase /

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

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*families-of-schools/start/(.+?)$ /index.php/toolkit/families-of-schools/start?school=$1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php/$1 [QSA,NC,L]