Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 Redirect Loop

8:39 am on Aug 26, 2013 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts: 97
votes: 0


This is what we have in our htaccess right now

RewriteEngine on
Options +FollowSymlinks

RewriteCond %{HTTP_HOST} ^example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.org$
RewriteRule ^/?$ "http\:\/\/example\.org\/index\.html" [R=301,L]

ErrorDocument 404 /index.html

What we want is to make the domain just redirect to http://example.org/ instead of the /index.html

I removed the "/index\.html" part, but it is ending in a redirect loop

I also tried this code

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

Still a redirect loop

Please advise

Thanks a lot
9:07 am on Aug 26, 2013 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
votes: 459

RewriteCond %{HTTP_HOST} ^example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.org$
RewriteRule ^/?$ "http\:\/\/example\.org\/index\.html" [R=301,L]

Oh, ouch. Oh, ouch.

#1 You are doing the exact opposite of what you want to do. In fact the "index.html" redirect should say something like

RewriteRule ^(([^/]+/)*)index\.html http://www.example.org/$1 [R=301,NS,L]

Some people will insist on a RewriteCond looking at THE_REQUEST as an alternative to the NS flag. But either way should work.

#2 The code as written will create an infinite loop for everything but HTTP/1.0 requests, because it says "if the host is example.org OR www.example.org" ... and what else would it be? Do you have subdomains that you're trying to exclude, or other domains that pass through the same htaccess?

Now, you do want a domain-name canonicalization redirect. But that's a separate RewriteRule. In general, the index redirect will be your second-to-last redirect while the canonicalization redirect is the very last redirect.

#3 Using the index page as your error document is not as calamitous as explicitly redirecting 404s to the index page. But wouldn't it be more helpful to your human users if you made a custom 404 page? They already know they're on your site; tell them something they don't know.
3:17 pm on Aug 26, 2013 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts: 97
votes: 0

Hi Lucy

A BIG thanks for your reply and help.

You were right, the RewriteRule ^(([^/]+/)*)index\.html http://www.example.org/$1 [R=301,NS,L] code fixed the loop problem.

2. This entire website www.example.org has been recently moved to a sub-domain go.example.org. Also there are additional sub-domains where blogs have been installed like uv1.example.org; uv2.example.org and so on.

There are no additional domains that pass through the same htaccess. We just wanted that all requests for www.example.org/index.html or example.org/index.html should be redirected to just example.org

After the website has moved to the sub-domain, there is nothing on example.org except a splash page that redirects users to the new location. So I don't think a canonical redirect on the root domain would matter now, right?

3. The index.html is actually acting as a custom 404 page since it is the splash page that directs users to the new location at go.domain.org

Thanks a lot once again!