Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Too many redirects



12:15 pm on Nov 23, 2010 (gmt 0)

5+ Year Member

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


1:12 am on Nov 28, 2010 (gmt 0)

10+ Year Member

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).



9:27 am on Nov 28, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

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.


10:11 am on Nov 28, 2010 (gmt 0)

5+ Year Member

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.


11:22 pm on Dec 1, 2010 (gmt 0)

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

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.


Featured Threads

Hot Threads This Week

Hot Threads This Month