WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Rewrite rule in .htaccess causes ∞ redirects (6 posts)

  1. jazbek
    Member
    Posted 3 years ago #

    I have found a large number of these errors in our apache log:

    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.

    I had our sysadmin enable LogLevel debug and found they were coming this scenario:

    [Wed Nov 10 17:24:59 2010] [debug] core.c(3063): [client xxx.xxx.xxx.xxx] r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /post-slug/&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /10/post-slug/&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /11/10/post-slug/&refer=http:/www.facebook.com/l.php
    [Wed Nov 10 17:24:59 2010] [debug] core.c(3069): [client xxx.xxx.xxx.xxx] redirected from r->uri = /2010/11/10/post-slug/&refer=http://www.facebook.com/l.php

    I looked at our .htaccess, and it seems to me like this rule is causing the problem?

    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

    This is one of the rules that is required for multi-site, though it seems like it causes a URL that ends in .php to never resolve, if the .php is not part of a filename, as in the above example.. which seems like it would be really common -- a facebook referral.

    Just wanted to bring this up and see what others think, is this a real issue? For now I am going to strip the &refer=xxx stuff out of the URL before it hits the WP rules.

  2. What's the FULL .htaccess and are you using subdomains or subfolders?

    Is this only happening on SOME links or all?

  3. jazbek
    Member
    Posted 3 years ago #

    Subdomains. Please check the apache debug log I pasted in my post (2nd block of "code") to see the type of URL that causes the problem redirect (it ends in .php, but it's not a file). Here is my .htaccess:

    <FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
    ExpiresDefault "access plus 2 hours"
    </FilesMatch>
    
    RewriteEngine On
    RewriteBase /
    
    <IfModule mod_security.c>
    <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off
    </Files>
    </IfModule>
    
    # BEGIN WPSuperCache
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    AddDefaultCharset UTF-8
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*
    RewriteCond %{HTTP_user_agent} !^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz" [L]
    
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
    RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
    RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*
    RewriteCond %{HTTP_user_agent} !^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html" [L]
    </IfModule>
    
    # END WPSuperCache
    
    # BEGIN WordPress
    
    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    RewriteRule ^(.+)$ $1/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    # END WordPress
  4. Change the WordPress bit to this for better SubDomain support:

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    # END WordPress

    The one you have is the old WPMU one, and while it should work, the simplified one here may work better :)

    You may need to re-save WP Super Cache settings (or flush your cache and go back) after the change. I can't remember...

  5. jazbek
    Member
    Posted 3 years ago #

    Thanks, yeah I was able to solve the problem on my own but I just wanted to bring this up to see if it was worth logging a bug for.

    However, I see that the new (good) rules you suggested are the same ones that WP 3.01 tells people to put in their site. Not sure how those old rules got in there as this is a new site.

    Thanks for the response!

  6. You're welcome!

Topic Closed

This topic has been closed to new replies.

About this Topic