Learn how to redirect a website’s visitors to another domain using an .htaccess
file in this quick and easy tutorial.
To always redirect a website’s visitors to the home (welcome) page of another domain, place the following lines of code at the beginning of a file named .htaccess
residing in the source domain’s folder:
<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>
In the above example, the source domain is example.org
and the destination domain is example.com
. Remember to change the domains within the code to your actual source and destination domains.
The above code in the .htaccess
file will cause all visitors to any web address on the source domain to be automatically redirected to the welcome page on the destination domain.
For example, visitors to https://www.example.org/products
would be redirected to https://www.example.com/
.
To redirect a website’s visitors to a matching page on a destination domain, use the following code instead:
<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>
In this example, visitors to https://www.example.org/products
would be redirected to https://www.example.com/products
.
You may also like:
Love our articles? HostM offers professional and helpful web hosting services with unlimited features and renewal rates that actually match our advertised rates.
From $2.98/mo
We can help you move your
email and websites as desired.