How to redirect a domain name using .htaccess

If your domain name is changed for some reason and you want users/search engines to redirect to new Location then add the below code in .htaccess file of your website.

Example:

If you want to redirect http://olddomain.com to http://www.newdomain.com

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]
</IfModule>

After you add above code in .htaccess file it will as also redirect links.
Example:

http://olddomain.com/archive/2019 will redirect to http://www.newdomain.com/archive/2019

Leave a Reply

Your email address will not be published. Required fields are marked *