dah85.com

*not* just another blog ;)

Redirecting domains with VestaCP

- Posted in Quick Tip by with comments

I have been looking for a way to redirect domain1.com to domain2.com even if the address is domain1.com/blah/random it will always redirect to domain2.com

We need to make a .htaccess file in the public_html folder and add the following:

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

If we want it to forward them like this, example1.com/blah to example2.com/blah, we'd use:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain1.com [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301,NC]