Forum Moderators: phranque

Message Too Old, No Replies

Infinite Redirect Loop without trailing slash

The page seems to redirect to itself

         

debc

11:33 am on Sep 18, 2012 (gmt 0)

10+ Year Member



I've been searching for an answer all day, I can't seem to figure this out.

When I Fetch my blog as Google(http://www.example.com/blog) WITHOUT a trailing slash at the end, I get this error:

The page seems to redirect to itself. This may result in an infinite redirect loop.
HTTP/1.1 301 Moved Permanently


When I Fetch my blog as Google WITH the trailing slash at the end(http://www.example.com/blog/), it is fine without errors.

When I pull it up in a browser comes up fine both with and without the trailing slash.

My .htaccess file in the root directory contains this:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

My .htaccess file in the blog directory contains this:

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_URI} ^.*/index.php/.* [NC]
RewriteRule ^index\.php/(.*)$ [mysite.com...] [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Do I have something incorrectly coded in these .htaccess files that could be causing this? Or is there something else I should look at? Thank you for any help!

phranque

12:01 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



have you checked your server access logs to see how many requests and what was being requested?

phranque

12:07 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



on further inspection i see several issues with your .htaccess files which we can address after we solve the subject problem.

debc

1:07 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



I'm a newbie with this, please forgive me! My website is on shared hosting. I just checked my account and found I have to set up site analytics before I can view the logs. I just did that, but I cant view them yet since I just set it up.
Is there any other way I can find how many requests and what is being requested? Thank you for your help!

g1smd

1:28 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The RewriteCond looking at REQUEST_URI should be looking at THE_REQUEST.

The index redirect in the blog folder runs after the non-www redirect in root leading to an unwanted multiple step redirection chain for non-www index requests.

Escape literal periods in patterns.

Your non-www/www redirect needs improvement.

Combine all your rules in the root htaccess file to guarantee the order they are run.

[edited by: g1smd at 1:32 pm (utc) on Sep 18, 2012]

phranque

1:31 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you could try a user agent switcher in your browser to see if it emulates googlebot.
if so then you can use a header checker to see the entire response status chain.
you can do this all with firefox add-ons.

debc

1:39 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



Thanks g1smd, I just changed the code but I'm still getting the same message that the page is redirecting to itself when I fetch the url without the trailing slash. (www.example.com/blog)

This is what I changed the code to:
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{THE_REQUEST} ^.*/index.php/.* [NC]
RewriteRule ^index\.php/(.*)$ http://www.example.com/blog/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

debc

6:32 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



Thanks Phranque. I tried the agent switcher in Firefox and this is what the header info generated:
#request# GET http://www.example.com/blog
GET /blog
#request# GET http://www.example.com/blog/
#redirect# GET /blog/

Does this look correct?

phranque

8:09 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what is the Location: header on the redirect response?

debc

8:32 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



This is what I found:

----------------------------------------------------------
http://www.example.com/blog/

GET /blog/ HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: wp-settings-2=editor%3Dhtml%26m8%3Do%26m9%3Do%26m1%3Do%26m4%3Dc%26m3%3Dc%26m2%3Dc%26m5%3Do%26m7%3Do%26m6%3Do; wp-settings-time-2=1345139702; __utma=10730418.2005803037.1262008709.1347982926.1347990963.112; _csoot=1268243256572; _csuid=X4b38dbb99d6f94b9; __utmz=10730418.1316713759.31.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __atuvc=19%7C34%2C0%7C35%2C7%7C36%2C1%7C37%2C21%7C38; __utmc=10730418

HTTP/1.1 200 OK
Date: Tue, 18 Sep 2012 20:18:57 GMT
Server: Apache
X-Pingback: http://www.example.com/blog/xmlrpc.php
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 7283
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
----------------------------------------------------------

phranque

8:38 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



a 200 OK status code in the response doesn't look like a redirect loop to me...

debc

8:50 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



I agree, there is no error when I pull up both urls in a browser:
http://www.example.com/blog (without trailing slash)
and http://www.example.com/blog/ (with trailing slash)

BUT, the only reason I found a redirect loop error is when I do a Google Fetch with http://www.example.com/blog (without trailing slash) it gives me the redirect loop error. When I do a Google Fetch with http://www.example.com/blog/ (with a trailing slash) it gives a 200 OK status code

Should I be concerned with this? Or should I just leave it alone?

lucy24

11:32 pm on Sep 18, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Wait. Backtrack. Is /blog/ a real, physical folder, or something used by WordPress code?

debc

11:34 pm on Sep 18, 2012 (gmt 0)

10+ Year Member



/blog/ is a real physical folder.

phranque

12:10 am on Sep 19, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



which url are you linking to internally?
do you have inbound links to the non-trailing-slash urls?
are you getting lots of googlebot requests for the non-trailing-slash urls (other than your fetch as googlebot requests?)

phranque

12:37 am on Sep 19, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



does your default directory index document possibly do a redirect?

truthfully i can't find anything in your directives posted that would cause either url to 301.

debc

12:47 am on Sep 19, 2012 (gmt 0)

10+ Year Member



Internally I link to /blog/

There are no inbound links to the non-trailing slash urls

I don't know if I am getting googlebot requests for the non trailing slash pages since I don't have access to the server logs yet(I just set it up today) Is there another way I can see if googlebot is requesting the non trailing slash urls?

Thanks!

lucy24

2:54 am on Sep 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When there is a request for /directory and it's a real, physical directory, mod_dir kicks in and does a Directory Slash Redirect to /directory/ with trailing slash. Can't help but feel that google is just being dimwitted for not recognizing that this is probably all that's happening.