Rick Skeels
Rick Skeels

Reputation: 513

Redirect all traffic from one domain to another

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

Upvotes: 11

Views: 22595

Answers (1)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

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]

Upvotes: 22

Related Questions