5 methods to redirect old domain to new domain

5-methods-to-redirect-old-domain-to-new-domain

When you migrate a site from one domain to another it is very important to move your traffic from your older domain to new domain. In this article we will see 5 methods to redirect old domain to new domain.

Why redirection is important when a site is migrated?

It is important that your all pages should be redirected to new domain properly otherwise you will lose your traffic. You will not only loose your traffic but also the existance in the search engines.

There are different ways to redirect an old domain to new domain using. Following are the 5 methods to redirect old domain to new domain:

  1. .htaccess
  2. HTML
  3. JavaScript
  4. PHP
  5. Server

1. Redirection using .htaccess

Add the following script in the .htaccess file:

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

Don’t forget to replace the olddomain and newdomain with the actual domain names.

Also see how to force https on a website using htaccess

2. Redirection using HTML

Create an index.html file and add the following piece of code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="refresh" content="time; URL=https://www.newdomain.com" />
    </head>
    <body> </body>
</html>

Don’t forget to replace the newdomain with your domain name.

3. Redirection using JavaScript

Create an index.html file and add the following code:

<script>
    window.location = "https://www.newdomain.com";
</script>

Don’t forget to replace the newdomain with your domain name.

4. Redirection using PHP

Create an index.php file and add the following code:

<?php
    header("location: https://www.newdomain.com");
?>

5. Redirection using server

Redirection using server is a bit tricky and requires some technical knowledge to do it. Here we will cover the option to apply redirections using cPanel options.

Open cPanel and in the search type “redirects”. This will filter the options and you will see “Redirects” under “Domains”:

cpanel-redirects

Click on the “Redirects” and it will take you to its options page:

cpanel-redirects-add-old-new-domain

If you want to permanently redirect domain then in the type select “Permanent (301)”.

Then select your old domain from the dropdown and if you want to apply redirection on specific directory then enter its name e.g. in our above image we have used “anyfolder”, you can replace it with your folder or keep it empty.

Next field is to write the address of new domain on which you want your traffic to reach.

You can select “Wild Card” redirects if there are sub-domains.

Once all settings are done, click the “Add” button and this will create server side redirection.

Related Posts