homepage Welcome to WebmasterWorld Guest from 54.198.157.6
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

    
301 doesn't redirect
want to force traffic from one domain to another
ArielZusya




msg:4373212
 12:55 pm on Oct 11, 2011 (gmt 0)

I'm struggling with redirection. We own two domains: uglydomain.com and prettydomain.com. For the longest time our site was only available at uglydomain.com. Recently we purchased prettydomain.com and would like to migrate traffic over to the new domain. Setting it up so folks who browse to prettydomain.com get our content was easy. Where I'm having trouble is with the old url. I'd like anyone who still attempts to access our site at uglydomain.com to be automatically pushed to prettydomain.com. I attempted to do this via 301 in a .htaccess file but I think I'm doing something wrong. Here's what I did:


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


When I browse to www.uglydomain.com I thought it would push me onto www.prettydomain.com (changing the url in my browser) but no such luck. Do I have the 301 right? What should happen? Thanks in advance for your assistance!

 

The_Fox




msg:4373308
 4:46 pm on Oct 11, 2011 (gmt 0)

Try this. Make sure you take backups.


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

[edited by: The_Fox at 4:48 pm (utc) on Oct 11, 2011]

The_Fox




msg:4373309
 4:47 pm on Oct 11, 2011 (gmt 0)

Can you also share the URl structure for the old and new domains? I assume they are the same.

ArielZusya




msg:4373314
 4:54 pm on Oct 11, 2011 (gmt 0)

That did it. Thanks!

lucy24




msg:4373399
 9:17 pm on Oct 11, 2011 (gmt 0)

Fox, can you explain this part?

RewriteCond %{HTTP_HOST} ^uglydomain\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.uglydomain\.com
RewriteCond %{HTTP_HOST} uglydomain\.com


It seems redundant, but obviously it isn't if the effect is different from the version without the third line.

btw, it should be possible to express the [OR] pair as

(www\.)?uglydomain\.com
g1smd




msg:4373410
 9:45 pm on Oct 11, 2011 (gmt 0)

This is more robust.

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


Redirect if requested hostname is not "exactly" www.example.com

Make sure you escape any literal periods in all RegEx patterns.

phranque




msg:4373856
 12:54 am on Oct 13, 2011 (gmt 0)


!^(www\.example\.com)?$

the '?' after the ')' makes the capture group optional, so hidden in g1smd's regexp is that it also matches when HTTP_HOST is exactly null.
this is a good thing as it handles the special case of HTTP/1.0 user agent requests.

HTTP_HOST for HTTP/1.0 browser:
http://www.webmasterworld.com/forum92/2240.htm [webmasterworld.com]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Webmaster General
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