When you migrate a site from one domain to another it is very important to move your traffic from your older domain to the new domain. In this article, we will see 5 methods to redirect an old domain to a new domain.
Table of Contents
Why redirection is important when a site is migrated?
Your all pages must be redirected to the new domain properly otherwise you will lose your traffic. You will not only lose your traffic but also your existence and ranking in the search engines. If you want to analyze the SEO of your site, please click to access our free SEO Analyzer tool.
There are different ways to redirect an old domain to a new domain. Following are the 5 methods to redirect an old domain to a new domain:
Redirect an old domain to a new domain
Let’s dive into the article to see 5 methods to redirect an old domain to a new domain.
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:
window.location = "https://www.newdomain.com";
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 a server (cPanel)
Redirection using a 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”:
Click on “Redirects” and it will take you to its options page:
If you want to redirect the domain then in the type permanently select “Permanent (301)”.
Then select your old domain from the dropdown and if you want to apply redirection on a 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.
The next field is to write the address of the 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.
Testing
Before deploying these techniques in your live projects, thorough testing is crucial. Make sure the implementation is cross-browser and is working on different devices.
Conclusion
You’ve mastered the art of redirect an old domain to a new domain. This knowledge opens the door to personalized redirection handling, providing a more intuitive and responsive user experience.