Skip to content

Redirect Whole Website to New Domain

How To Redirect Whole Website to New Domain Without Losing Backlinks

Redirect entire Website to New DomainWhen you change domains, any old links that other people have made are likely to remain and very unlikely to be updated. You should ask for an update if you can but it will be a low priority on anyone's 'To Do' list.

This is how you make sure that visitors and search engines will end up on your new website at its new address. If you have plenty of good backlinks it will be good for SEO too.

This is the way to redirect a site using htaccess - there are ifs and buts to the process. If this is the situation, do that etc.

This is also known as a 301 Redirect or a Permanent Redirect.

Once you have done a 301 redirect you won't be able to look at the old site yourself so be sure you have finished all the steps to move the site and no longer need to reference the old one.

Here are a few scenarios:

  • 1. Your website is 'yourdomain.com' and all the files are in the root of the directory.
  • 2. You have a landing page and the remainder of your website is in a subdirectory, e.g.'blog'.
  • 3. Your website shows on your main domain but the files that run it are in another directory, e.g. when you run WordPress in a sub-directory.
  • 4. Part of your website is a subdomain such as 'tips.yourdomain.com' just like this very site.
  • 5. Your website is a combination of scenarios - Then you should piece the redirection information together with [OR] as you will see.

This Is What You Do

My Directions apply to a Linux server and assume you know how to access your files either by ftp or directly.

NOTE: Your server MUST have the Apache ModRewrite module turned on – check this with your server administrator first or this won't work!

Take a backup of your .htaccess file or rename it .htaccess file_ xxx

Make a new blank .htaccess file or edit a copy of the original.

Needless to say, but I will. Remember to use your own domain names and don't forget the tld (.com .net etc.)

Scenario 1. Your website is 'yourdomain.com' and all the files are in the root of the directory.

Copy this, but take note that the code is run in order, and if a redirect is found, it will not run the second redirect. Swap the order of lines according to which is the main protocol of  your site. AND change the last line to suit your preference at the new site, with or without the www. and the http:// or https://

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

Upload the file to the ROOT of your website, it's usually public_html.

Scenario 2. You have a landing page in the Root and the remainder of your website is in a sub-directory, e.g.'blog'.

Copy the above (first) code, make appropriate adjustments as mentioned above and upload the file to the ROOT of your website.

Next, Make a copy of the .htaccess file for the sub-directory. You might not need to do this for every subfolder but it will  be a needed if it is powered by WordPress.

Upload the file to the SUBFOLDER of your website.

You probably have to do it for the third scenario, And definitely for the fourth as well.

Scenario 3. Your website shows on your main domain but the files that run it are in another directory, e.g. when you run WordPress in a sub-directory.

Next, Make a second .htaccess file for the sub-directory. Following the same directions for the order of lines, copy the file and Upload the file to the SUBFOLDER of your website.

Scenario 4. Part of your website is a subdomain such as 'tips.yourdomain.com'.

Copy the above (first) code, make appropriate adjustments as mentioned above and upload the file to the ROOT of your website. That will take care of your main domain. Pick and choose where to put the file for any variations

For the  subdomain ( oldsub.olddomain.com), locate the folder related to it, where you keep the files. Following all the backup recommendations first, make a new .htaccess file and copy this:

Options +FollowSymlinks 
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsub.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsub.olddomain.com$
RewriteRule (.*)$ http://newsub.newdomain.com/$1 [R=301,L]

Upload the file to the SUB-DOMAIN FOLDER of your website.

Again, If you don't want to lose the original .htaccess file, be sure to rename it first.

You might not need to do this for a subfolder in the subdomain but it might be  needed if it is powered by WordPress.

If it all works you can celebrate with old friends at your new location:)

Embed from Getty Images

Let me know it it works for you too - share thoughts, corrections and improvements to this in the comments.