Skip to content

How do I redirect from one domain to another?

To redirect from one domain to another, you can use an .htaccess file in the root directory of the domain you want to redirect. Add the following lines to the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]

This will redirect all requests from olddomain.com to newdomain.com with a 301 redirect.

If you want to redirect a subdomain such as an old application to a new application, you can use the following lines:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldapp\.example\.com$ [NC]
RewriteRule ^(.*)$ https://newapp.example.com/$1 [R=301,L]

This will redirect all requests from oldapp.example.com to newapp.example.com with a 301 redirect.