23

My website has been slowed down a little last couple of days. I've looked into my error log and found lots of these:

[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

How can I find what is causing this?

It seems a loop around index.php, with the exception of the last one which is an image, most likely linked within one of my pages (not index).

I'm using codeigniter, which is a mvc framework and everything goes trough the index.php file, so it's a bit harder to understand where it goes wrong.

Apparently it has something to do with .htaccess (it's been mentioned in couple of blogs).

Here is my .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

I did some changes to my .htaccess (basically I've removed to top conditions before the last block) and now I get this:

[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

Now it seems there is the img directory in the mix, but I dont have that directory at all. There used to be a subdomain which I used for images with this address.

img.mysite.com => mysite.com/files/images/

I don't use it anymore because of some slowness and complications. Now I just use the real path to images.

Why do i get this subdomain in the loop? I don't have access to the guy who configured this server. Could it be some config / setting that he has done?

anubhava
  • 761,203
  • 64
  • 569
  • 643
max
  • 3,614
  • 9
  • 59
  • 107
  • What is cuzing that is written in the log. You need to do the logging like the error message told you. Also you might want to learn about the [L] flag: [Mod_Rewrite unexpected behavior L flag](http://stackoverflow.com/q/11484739/367456) – hakre Sep 28 '13 at 20:29
  • Can you adding `Options -MultiViews` on top of your .htaccess? – anubhava Sep 29 '13 at 07:40
  • @anubhava yes i can ... so this line , what does it do ? – max Sep 29 '13 at 12:24
  • This turns off problematic `MultiViews` option. Please try it out and let me know. – anubhava Sep 29 '13 at 12:25
  • Did `Options -MultiViews` help? – anubhava Oct 01 '13 at 17:46
  • @anubhava thanx but no i still get the error – max Oct 01 '13 at 23:18
  • Alright thanks for your response. Can you try commenting out `ErrorDocument 404 index.php` line (for testing only) and see if this fixed looping? – anubhava Oct 02 '13 at 20:35
  • Another thing to try is adding this condition `RewriteCond %{ENV:REDIRECT_STATUS} ^$` just before `RewriteRule ^(.*)$ index.php?/$1 [L]` line. – anubhava Oct 02 '13 at 21:01
  • @anubhava ... this seems to be worikng ... i get lots of `file doesn't exist` now (and they are all from same address : `/public_html/img/home`) but i dont get that looping error ... what does it do exactly ? – max Oct 04 '13 at 18:52
  • `RewriteCond %{ENV:REDIRECT_STATUS} ^$` does prevent looping by checking internal mod_rewrite variable `REDIRECT_STATUS` which is set to `200` after first internal redirect. – anubhava Oct 04 '13 at 18:54
  • 1
    Next time you offer a bounty on a question: Please take some time formatting your question, removing txtspk like 'becuz' and '......', use capitals at the beginning of every phrase, a comma before concatenation words like 'but' and 'and' and end your phrases properly with a full stop. Even those simple things make a question soo much better. – Sumurai8 Oct 04 '13 at 18:59

7 Answers7

65

To prevent infinite looping add an extra RewriteCond line on top of your rule like this:

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

RewriteCond %{ENV:REDIRECT_STATUS} ^$ prevents looping by checking an internal mod_rewrite variable REDIRECT_STATUS which is set to 200 after first successful internal redirect.

Reference: Apache mod_rewrite Introduction

Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643
5

Looking to your htaccess I see that you use it to remove index.php from your url, but you are missing the RewriteBase, you can add it after the RewriteEngine On directly like this:

<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

So, RewriteBase / will be valid if your application/website is not on a subdomain. However, if it is then you might need to add the folder name after the / symbol.

mamdouh alramadan
  • 8,349
  • 6
  • 36
  • 53
  • thanx , i've done this before .. only difference is i get error like this `redirected from r->uri = /index.php` till the last one – max Oct 04 '13 at 18:50
4

The last block:

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

Is most likely re-injecting a changed request URI over and over again which could cause such an internal redirect error. Check the error log with debugging level enabled to trace each redirect step, it makes things much more visible and will tell you exactly which redirect rules are triggering it.

For a detailed description and how to prevent the re-injection, please see:

The solution outlined there actually should do it in your case as well. It's pretty much the same, even the file-names are identical.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • thanx , i'm fairly good programer but i suck at webmastering , networking , handling servers , htaccess , english ! ... it seems a detailed answer is in the second link that you gave but while i'm getting hold of concepts and whats going on could you pleas simply tell me if this looping is happening for all of the link of my website or just the one that have a specific rules ... btw someone else hase wroted this htaccess , im just the programmer – max Sep 28 '13 at 20:44
  • For a programmer: Consider there is a while loop around that. And it does not exit unless the URL does not change any longer. As the body changes the URL everytime (it always adds `index.php?/` in front), the loop is never existed. Luckily apache gives you an error otherwise you would have ended up in an endless loop which would lock up your servers resources after some little requests. – hakre Sep 28 '13 at 20:49
  • I doubt that block is causing any problems. The `!-f` and `!-d` conditions will prevent the last block from executing more than once (assuming index.php is an actual file, the `!-f` condition won't match and the rewrite won't happen) – Sam Dufel Sep 28 '13 at 20:50
  • 1
    You now need to add a condition to not change the URL when you already changed it, like if it starts with `index.php?` already. This is done by: `RewriteCond %{REQUEST_URI} !=/index.php`, add that condition. – hakre Sep 28 '13 at 20:51
  • @Sam Dufel: Well I can't perfectly say *unless* the OP provides the debug log data which OP *still* misses to provide even the error message told otherwise and I also did in the answer and in comments. From my experience when such errors occur, it's most likely missing to see that the L flat is not the last resort. For a quick solution without trouble-shooting the concrete configuration on the concrete server, most often a check if the server supports the END flag can resolve this in a hard exit without further dealings if available. – hakre Sep 28 '13 at 21:02
  • @hakre - it sounds more likely there's an error somewhere in the application layer on a particular page. If those rules in the htaccess were actually looping, every page except index.php would die with a 500 error. – Sam Dufel Sep 28 '13 at 21:03
  • @hakre would you pleas tell me where can i find/enable `LogLevel` .. i've red the document in here http://httpd.apache.org/docs/current/mod/core.html#loglevel ... i know i should add `LogLevel debug` to some config file ... but i cant find out where . – max Sep 28 '13 at 22:49
  • It's worth noting that all the work (intended to be) done by the mod_rewrite block can be more economically done by the 404 handler as specified in the !mod_rewrite block – symcbean Sep 28 '13 at 23:27
  • 1
    @SamDufel: *"10 internal redirects"* - please take notice of the word *"internal"* in front of redirects. That are those by mod_rewrite without passing the request to the application. The external redirect loops are normally detected by the browser, not the server. – hakre Sep 29 '13 at 05:20
  • @max: The config-file you're looking for is the one from the webserver. It's in this field: *"Context: server config, virtual host"*, that means either in the server configuration file or inside your virtual host config. Contact your system administrator for those sections. – hakre Sep 29 '13 at 05:23
  • @hakre thanx i did it , also i've replaced to old error with new ones . as you said it seems a loop around index.php , with the exeption of last one which is an image , most likely linked within one of my pages (not index) – max Sep 30 '13 at 03:15
  • There is a directive called `RewriteBase`. Read a little about it and choose the right value for your setup. It might already solve your issue. If not, introduce the index.php check I linked since the beginning. The rewrite log seems to confirm my first assumption which rule is causing this. You can also find out by commenting it out for trouble shooting. – hakre Sep 30 '13 at 05:12
3

You can also use the END flag, instead of the L flag:

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

Using the [END] flag terminates not only the current round of rewrite processing (like [L]) but also prevents any subsequent rewrite processing from occurring in per-directory (htaccess) context.

This does not apply to new requests resulting from external redirects.

mikiqex
  • 5,023
  • 2
  • 24
  • 22
1

Maybe it is a dummie awnser, but I just empty my .htaccess and configure permalinks again. Everything works after that.

0

I had some performance issues in Apache when the loglevel was debug ... Moving back to Error mode speedup the requests

foxdanni
  • 199
  • 1
  • 19
0

I commented out the "RewriteBase /drupal" in my .htaccess file  present in drupal root folder. It works for me.