homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

301 Redirect Loop

5+ Year Member

Msg#: 4604911 posted 8:39 am on Aug 26, 2013 (gmt 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



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4604911 posted 9:07 am on Aug 26, 2013 (gmt 0)

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.


5+ Year Member

Msg#: 4604911 posted 3:17 pm on Aug 26, 2013 (gmt 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!

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