What I am trying to do is automatically redirect the domain for one of my sites

www.domain1.com to www.domain2.co.uk

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain1.com\. [NC]
RewriteRule (.*) http://%www.domain2.com\%{REQUEST_URI} [R=301,NC,L]

I have looked over the site for the answer and the above is my code that I edited from another answer, but it doesn't work.

I would like it in a .htaccess file - is this the best way of doing it?

Thanks

share|improve this question
    
are both domain hosted on same server (same cPanel for example)? or domain1.com is hosted on another server? – user1646111 Jan 28 '13 at 15:52

To redirect from www.domain1.com to www.domain2.co.uk, you may try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^(.*)$ http://www.domain2.co.uk/$1 [R=301,NC,L]
share|improve this answer
    
I corrected the destination domain in the rule per the original post. – David Ravetti Jan 28 '13 at 16:12
    
@David Thanks a lot. I was looking at the rewrite rule `domain2.com` but I agree it should be the one in the question. – Felipe Alameda A Jan 28 '13 at 16:19
    
From an SEO standpoint, is it a bad idea to do something like this or will it not have an effect? – DavidB Jan 10 '16 at 21:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.