homepage Welcome to WebmasterWorld Guest from 54.198.224.121
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
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
tr95




msg:3030928
 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, http://12.34.56.78/contact.htm is redirected to http://www.example.com/contact.htm, but http://12.34.56.78 is not redirected, and http://12.34.56.78/ 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]
[/edit][/1]

 

jdMorgan




msg:3030970
 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.

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved