homepage Welcome to WebmasterWorld Guest from 54.167.179.48
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Too many redirects
moroandrea



 
Msg#: 4234014 posted 12:15 pm on Nov 23, 2010 (gmt 0)

All right, I'm going to give up on this as it's three days that I'm reading and testing solution.

I was having dozens of online rules in my httpd.conf file and all are working fine as soon as I remove the last rule that attempt to trap "all the rest of the path" non rewrited previously.

Initially I was thinking to some problems with the rules, but leaving ONLY the following

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/.*$ /404.php [L,R=301]

results in both Firefox and Chrome claim a message like "This web page has a redirect loop." or "The page isn't redirecting properly".

However, if I have a look at the RewriteLog file it looks like the rule is correctly executed as the log contain the following

127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (3) applying pattern '^/.*$' to uri '/testrere/'
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (4) RewriteCond: input='/testrere/' pattern='!-f' => matched
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (4) RewriteCond: input='/testrere/' pattern='!-d' => matched
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (2) rewrite '/testrere/' -> '/404.php'
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (2) explicitly forcing redirect with [us.test.com...]
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (1) escaping [us.test.com...] for redirect
127.0.0.1 - - [23/Nov/2010:12:10:59 +0000] [us.test.com/sid#22e775c0][rid#23033540/initial] (1) redirect to [us.test.com...] [REDIRECT/301]

However, the above block of text is repeated another 20 times, with the only exception that from the second time onward the incoming request file is the 404.php file.

I really don't understand why such kind of strange behaviour.

Someone can help me understand where is my fault?

 

sublime1

10+ Year Member



 
Msg#: 4234014 posted 1:12 am on Nov 28, 2010 (gmt 0)

The rewrite rule you specify says: if the filename in the request is not a file or directory, and it does start with a / then do an external redirect with HTTP status 301 and stop processing rules.

Unless you have a file in your document root called 404.php, the problem is likely that the path "/404.php" also matches these rules.

And if so, why are you doing a 301 redirect? Why not a 404 (R=404).

Tom

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4234014 posted 9:27 am on Nov 28, 2010 (gmt 0)

Never ever "redirect" to a 404 page. When you do this, you are returning a 301 response for content that is not found. The correct response is an IMMEDIATE 404 status for the original URL request.

By using a redirect, you suddenly have infinite URL space in your site, and search engines do not like this. Their bots can get "stuck" on your site, and will abort before they have indexed everything.

moroandrea



 
Msg#: 4234014 posted 10:11 am on Nov 28, 2010 (gmt 0)

Well, the correct answer was the one provided by sublime1.

Of course I stuck just a 404.php for testing purpose, the real path to be returned was a different one, similar to one of another rewriterule contained. But I changed it slightly just to locate the entry into the rewritelog file.

Thanks to both, anyway.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4234014 posted 11:22 pm on Dec 1, 2010 (gmt 0)

Both answers are correct, in different ways. Do not redirect missing resources to any page, unless you do not care about your search engine rankings.

Use the standard ErrorDocument handlers for missing resources, so that your server will return a proper 404-Not Found response. If you redirect, your server will return a 301 redirect response followed by a 200-OK response, which means that *any* URL requested from your site will result in a 200-OK response... Infinite URL-space, search engines arbitrarily limiting their crawling to avoid that infinitie space, loss of search rankings... Bad.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved