Forward one domain to another using mod_rewrite and .htaccess

How to use the .htaccess file to forward to a different domain.

Within the mod_rewrite section of your .htaccess file, add the following lines:

RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

This automatically forwards any users from http://yoursite.co.uk to http://yoursite.com. This can also be used to forward multiple domains:

RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^yoursite\.info$ [OR]
RewriteCond %{HTTP_HOST} ^yoursite\.biz$ [OR]
RewriteCond %{HTTP_HOST} ^yoursite\.eu$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

If any of the RewriteCond conditions apply, then the RewriteRule is executed.

Was this useful?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.