11

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

1
  • are both domain hosted on same server (same cPanel for example)? or domain1.com is hosted on another server?
    – user1646111
    Jan 28, 2013 at 15:52

1 Answer 1

22

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]
3
  • I corrected the destination domain in the rule per the original post. Jan 28, 2013 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. Jan 28, 2013 at 16:19
  • From an SEO standpoint, is it a bad idea to do something like this or will it not have an effect? Jan 10, 2016 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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