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

时间:2013-09-28 20:26:46

标签: php apache .htaccess codeigniter error-handling

过去几天我的网站放慢了一点。我查看了我的错误日志,发现了很多这些:

[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/

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

为什么我在循环中获得此子域名?我没有权限配置此服务器的人。可能是他做过的配置/设置吗?

7 个答案:

答案 0 :(得分:48)

要防止无限循环,请在规则之上添加额外的RewriteCond行,如下所示:

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

RewriteCond %{ENV:REDIRECT_STATUS} ^$通过检查首次成功进行内部重定向后设置为200的内部mod_rewrite变量REDIRECT_STATUS来阻止循环。

参考:Apache mod_rewrite Introduction

答案 1 :(得分:4)

最后一个街区:

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

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

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

solution outlined there实际上也应该在你的情况下这样做。它几乎相同,即使文件名相同。

答案 2 :(得分:3)

期待您的htaccess我看到您使用它从您的网址中删除了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

因此,如果您的应用程序/网站不在RewriteBase /subdomain将有效。但是,如果是,则可能需要在/符号后面添加文件夹名称。

答案 3 :(得分:1)

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

答案 4 :(得分:1)

您也可以使用END flag代替L标志:

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

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

     

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

答案 5 :(得分:0)

当loglevel调试时,我在Apache中遇到了一些性能问题...回到错误模式加速请求

答案 6 :(得分:0)

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