How to redirect to another domain using .htaccess

Learn how to redirect a website’s visitors to another domain using a .htaccess file in this quick and easy tutorial.

Only redirect to the home page of the destination domain

To always redirect a website’s visitors to the home page of another domain:

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteCond %{HTTP_HOST} ^example.org$ [NC,OR]
	RewriteCond %{HTTP_HOST} ^www.example.org$ [NC]
	RewriteRule (.*) https://www.example.com/ [R=301,L]
</IfModule>

For example, visitors to https://www.example.org/products would be redirected to https://www.example.com/.

Redirect to the matching page on the destination domain

To redirect a website’s visitors to a matching page on a different domain:

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteCond %{HTTP_HOST} ^example.org$ [NC,OR]
	RewriteCond %{HTTP_HOST} ^www.example.org$ [NC]
	RewriteRule (.*) https://www.example.com/$1 [R=301,L]
</IfModule>

For example, visitors to https://www.example.org/products would be redirected to https://www.example.com/products.


Love our articles? HostM offers professional and helpful web hosting services with unlimited features and renewal rates that actually match our advertised rates.