请求超出了 10 个内部重定向的限制


Request exceeded the limit of 10 internal redirects

我的网站最近几天有点慢了。我查看了我的错误日志,发现了很多:

[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 框架,一切都通过索引.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/

由于一些缓慢和复杂,我不再使用它了。现在我只使用图像的真实路径。

为什么我会在循环中获取此子域?我无法访问配置此服务器的人。可能是他所做的一些配置/设置吗?

为了防止无限循环,请在规则顶部添加额外的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 来防止循环。

参考:阿帕奇mod_rewrite简介

查看您的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 /将有效。但是,如果是,则可能需要在/符号后添加文件夹名称。

最后一个块:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

很可能是一遍又一遍地重新注入更改的请求 URI,这可能会导致此类内部重定向错误。检查启用了调试级别的错误日志以跟踪每个重定向步骤,它使事情更加可见,并会准确地告诉您哪些重定向规则触发了它。

有关详细说明以及如何防止再次注射,请参阅:

  • Mod_Rewrite意外行为 L 标志

那里概述的解决方案实际上也应该在您的情况下做到这一点。它几乎相同,甚至文件名也相同。

您也可以使用 END 标志,而不是 L 标志:

RewriteRule ^(.*)$ index.php?/$1 [END]

使用 [END] 标志不仅会终止当前一轮的重写处理(如 [L](,还会阻止任何后续重写处理在每个目录 (htaccess( 上下文中发生。

这不适用于由外部重定向产生的新请求。

也许它是一个虚拟的遮阳篷,但我只是清空我的.htaccess并再次配置永久链接。在那之后一切都会起作用。

调试日志级别时,我在 Apache 中遇到了一些性能问题......返回错误模式可加快请求速度

我在drupal根文件夹中的.htaccess文件中注释掉了"RewriteBase/drupal"。它对我有用。