homepage Welcome to WebmasterWorld Guest from
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

301 redirect in .htaccess for unique IP address
Home page only not redirecting to www.site.com

10+ Year Member

Msg#: 3030926 posted 2:14 am on Aug 2, 2006 (gmt 0)

I moved my sites to unique IP addresses, as recommended in this forum. After doing so, I edited my .htaccess files to redirect requests for each unique IP to the appropriate [domain] to prevent Google from indexing both the IP address and the [domain].

This worked fine on one web host. On another web host, all pages other than the home page are redirected when the IP address is typed into a browser command line. However, the home page is not redirected. Thus, for example, is redirected to http://www.example.com/contact.htm, but is not redirected, and appears in the browser command line instead of http://www.example.com/.

This is what the top of my .htaccess file looks like (FrontPage extensions). (The non-www to www and index.html to / redirects work fine.)


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^12\.34\.56\.78
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

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

# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*


Can anyone suggest a solution?

[edited by: jdMorgan at 3:03 am (utc) on Aug. 2, 2006]
[edit reason]
[1][edit reason] Example.com [/edit]



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

Msg#: 3030926 posted 3:06 am on Aug 2, 2006 (gmt 0)

Actually, that looks like it should work as-is, so let me ask a basic question: Did you explicitly flush your browser cache before testing?

There's no reason that your code (as shown) should differentiate between a request for "/contact.htm" and one for "/".

Once this main problem is fixed, however, I would suggest moving your current first rule below your current third rule, so that a double-redirect is not performed if "example.com/index.html" is requested.


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