请求超出了 10 个内部重定向的限制
Posted
技术标签:
【中文标题】请求超出了 10 个内部重定向的限制【英文标题】:Request exceeded the limit of 10 internal redirects 【发布时间】:2013-10-04 23:09:20 【问题描述】:我的网站最近几天速度变慢了。我查看了我的错误日志,发现了很多:
[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] 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.
[Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /images/2013/02/600x376_0.076827001313237200_pixnaz_ir_1.jpg
我怎样才能找到造成这种情况的原因?
这似乎是一个围绕 index.php 的循环,除了最后一个是图像,很可能链接在我的一个页面中(不是索引)。
我正在使用 codeigniter,它是一个 mvc 框架,一切都通过 index.php 文件进行,因此很难理解哪里出错了。
显然它与 .htaccess 有关(在几个博客中都提到过)。
这是我的 .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 index.php
</IfModule>
AddType image/x-windows-bmp bmp
我对我的 .htaccess 做了一些更改(基本上我已经在最后一个块之前删除了***条件),现在我得到了这个:
[Wed Oct 02 00:10:07 2013] [error] [client 66.249.74.60] 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.
[Wed Oct 02 00:10:07 2013] [debug] core.c(3120): [client 66.249.74.60] r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /home/mysite/domains/mysite.com/public_html/index.php/img/images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
[Wed Oct 02 00:10:07 2013] [debug] core.c(3126): [client 66.249.74.60] redirected from r->uri = /images/2013/07/irwm_mysite_47b49a36d251fea382ba6b494fd3532ea75c78e6.jpg
现在似乎混合了img
目录,但我根本没有那个目录。曾经有一个子域,我用这个地址存放图片。
img.mysite.com => mysite.com/files/images/
由于一些缓慢和复杂性,我不再使用它。现在我只使用图像的真实路径。
为什么我会在循环中获得这个子域?我无权访问配置此服务器的人。会不会是他做的一些配置/设置?
【问题讨论】:
日志中写的 cuzing 是什么。您需要像错误消息告诉您的那样进行日志记录。此外,您可能想了解 [L] 标志:Mod_Rewrite unexpected behavior L flag 你能在你的 .htaccess 上添加Options -MultiViews
吗?
@anubhava 是的,我可以......所以这条线,它有什么作用?
这会关闭有问题的MultiViews
选项。请尝试一下并告诉我。
下次你提供一个问题的赏金:请花一些时间格式化你的问题,删除像'becuz'和'......'这样的txtspk,在每个短语的开头使用大写字母, 在“but”和“and”等连接词之前的逗号,并以句号正确结束您的短语。即使是这些简单的事情也会使问题变得更好。
【参考方案1】:
最后一个区块:
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
很可能一遍又一遍地重新注入更改的请求 URI,这可能会导致此类内部重定向错误。检查启用调试级别的错误日志以跟踪每个重定向步骤,它使事情更加明显,并会准确告诉您哪些重定向规则正在触发它。
详细说明及如何防止重注,请参见:
Mod_Rewrite unexpected behavior L flagsolution outlined there 实际上也应该在您的情况下这样做。几乎相同,甚至文件名都相同。
【讨论】:
thanx,我是一个相当优秀的程序员,但我在网站管理、网络、处理服务器、htaccess、英语方面很烂! ...似乎在您提供的第二个链接中提供了详细的答案,但是当我掌握概念和发生了什么时,您能否简单地告诉我这个循环是否发生在我网站的所有链接或只是有特定规则的那个……顺便说一句,其他人写了这个 htaccess,我只是程序员 对于程序员:考虑有一个while循环。除非 URL 不再更改,否则它不会退出。由于主体每次都会更改 URL(它总是在前面添加index.php?/
),因此循环永远不会存在。幸运的是 apache 给了你一个错误,否则你会陷入一个无限循环,在一些小请求之后会锁定你的服务器资源。
我怀疑该块是否会导致任何问题。 !-f
和 !-d
条件将阻止最后一个块执行多次(假设 index.php 是一个实际文件,!-f
条件将不匹配并且不会发生重写)
您现在需要添加一个条件以在您已经更改 URL 时不更改它,例如它已经以 index.php?
开头。这是由:RewriteCond %REQUEST_URI !=/index.php
完成的,添加该条件。
@SamDufel: "10 internal redirects" - 请注意重定向前的 "internal" 一词。那是 mod_rewrite 没有将请求传递给应用程序的那些。外部重定向循环通常由浏览器检测,而不是服务器。【参考方案2】:
在调试日志级别时,我在 Apache 中遇到了一些性能问题...回到错误模式可以加快请求速度
【讨论】:
【参考方案3】:查看您的 htaccess,我看到您使用它从您的 url 中删除 index.php
,但是您缺少 RewriteBase
,您可以像这样直接在 RewriteEngine On
之后添加它:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
AddType image/x-windows-bmp bmp
因此,如果您的应用程序/网站不在subdomain
上,RewriteBase /
将有效。但是,如果是,那么您可能需要在 /
符号之后添加文件夹名称。
【讨论】:
thanx ,我以前做过这个..唯一的区别是我得到这样的错误redirected from r->uri = /index.php
直到最后一个【参考方案4】:
为了防止无限循环,在规则顶部添加一个额外的 RewriteCond
行,如下所示:
RewriteCond %ENV:REDIRECT_STATUS ^$
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %ENV:REDIRECT_STATUS ^$
通过检查内部mod_rewrite
变量REDIRECT_STATUS
来防止循环,该变量在首次成功内部重定向后设置为200。
参考:Apache mod_rewrite Introduction
【讨论】:
【参考方案5】:也许它是一个假遮阳篷,但我只是清空我的 .htaccess 并再次配置永久链接。之后一切正常。
【讨论】:
【参考方案6】:您也可以使用END flag,而不是 L 标志:
RewriteRule ^(.*)$ index.php?/$1 [END]
使用 [END] 标志不仅会终止当前轮次的重写处理(如 [L]),而且还会阻止任何后续的重写处理在每个目录 (htaccess) 上下文中发生。
这不适用于由外部重定向产生的新请求。
【讨论】:
【参考方案7】:我在 drupal 根文件夹中的 .htaccess 文件中注释掉了“RewriteBase /drupal”。它对我有用。
【讨论】:
以上是关于请求超出了 10 个内部重定向的限制的主要内容,如果未能解决你的问题,请参考以下文章
.htaccess 一致“请求超过了 10 个内部重定向的限制...”(包含代码)