Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 973
Rick Skeels Avatar asked Jan 28 '13 15:01

Rick Skeels


People also ask

Can we redirect one domain to another domain?

URL redirect (URL forwarding) allows you to forward your domain visitors to any URL of your choice (to a new domain or a different website). You can set 301 (Permanent), 302 (Unmasked), and Masked (URL Frame) redirects for the domain names pointed to BasicDNS, PremiumDNS or FreeDNS.


1 Answers

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]
like image 69
Felipe Alameda A Avatar answered Jan 04 '23 09:01

Felipe Alameda A