Home » Internet » How to redirect old website domain to new domain using .htaccess file

How to redirect old website domain to new domain using .htaccess file



Have you just changed your domain name and now would like to redirect every link on the old domain name to a reciprocal link on the new domain, something like, http://olddomain.com/existing-link to http://newdomain.com/existing-link? Normally you can use the temporary redirection error (302) or permanent redirection error (301) in your .htaccess file to redirect every visitor of the old domain to the new domain. Initially, let’s use the permanent redirection error to redirect the old website domain to new domain, using .htaccess. The .htaccess file normally exists in your root folder. Download it in order to modify it, or if it doesn’t exists, open your favorite text editor and create this file.

Normally, when you want to redirect just one link, you use this line:

redirect 301 /existing-link/ http://newdomain.com/existing-link

But if you want to redirect every link to a link on the new domain, use the following lines:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]:

After adding these lines you have to upload the .htaccess file to the root folder of the old domain.