Forward one domain to another using mod_rewrite and .htaccess

23rd May 2012

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 (.*)$1 [R=301,L]

This automatically forwards any users from to 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 (.*)$1 [R=301,L]

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

Questions? Comments? I’m @opdavies on Twitter.

Tags: .htaccess, apache, code, drupal, mod_rewrite

About the Author

Picture of Oliver

Oliver Davies is a full-stack Web Developer and System Administrator based in the UK. He is a Senior Developer at Microserve and a part-time freelancer specialising in Drupal, Symfony and Laravel development and Linux systems administration.