Maab S.
10min Read

How to redirect a domain to another domain

How to redirect a domain to another domain

Imagine you have recently rebranded your business with a fresh new name and a sleek new website. You have also registered a new domain that more aptly reflects your brand. But what happens to your old domain? Visitors who bookmarked it, or search engines that still have it indexed, will need to be directed to your new domain. Of course, you don’t want to be managing two separate sites. Get a dedicated server.

Fret not. There’s an easy way to redirect all the traffic from your old domain to the new one. It’s called domain redirection. In this guide, we will cover everything you need to know about it. 



What is Domain Redirection?

Domain redirection, also known as domain forwarding, is a technique that directs visitors from one domain name (source domain) to a different domain name (target domain). When someone types in or clicks on the source domain, they are automatically taken to the target domain. 


Types of Domain Redirects

There are three main types of redirects, each with a different purpose and methodology:

301 Redirect 

This is the most common type of redirect. It tells search engines and browsers that your domain has permanently moved to a new location. It’s the best option for SEO because it passes most of the original page’s ranking power to the new one.

When a user tries to access your old domain, the server responds with a special status code (301) that tells the browser: “This page has permanently moved. Go to the new location instead.” The browser then automatically redirects the user to your new website. 

To achieve a 301 Redirect, you need to add a rule in the server’s configuration file (like .htaccess for Apache or nginx.conf for Nginx) or use a redirect module in a content management system (CMS). We will share a step-by-step guide for this in a later section.

302 Redirect 

This type of redirect is used for temporary situations, like when your website is undergoing maintenance, or has temporarily moved to a new location. Similar to a 301 Redirect, the server responds with a status code (302) that instructs the browser to go to the new location.

The key difference here is that the search engines will not update their records for 302 redirects. They will keep the original URL in their index and continue to rank it. So, if your move is permanent, using a 302 Redirect is not recommended.

To set up a 302 Redirect, you will have to update the server’s configuration file or CMS. Detailed guide in a later section. 

Meta Refresh Redirect 

This is a less commonly used type that instructs the browser to redirect after a certain amount of time, usually a few seconds. It involves embedding a small piece of code within the HTML of your old website.

The HTML code tells the browser to automatically refresh the page after a set delay and then redirect the user to the new location. Even though meta refreshes do achieve redirection, they can be clunky and bad for user experience

To implement a meta refresh, you can add the following HTML meta tag to the head of your old page:

<meta http-equiv="refresh" content="5;url=https://www.newdomain.com">

Reasons to Redirect a Domain

Here are some common scenarios where you’d need to redirect a domain to another one:

Rebranding

After someone changes the name or brand of their business, they often get a new domain that reflects the new identity. In these cases, a domain redirect ensures that the visitors who remember the old web address can still find the business online, and are aware of the rebranding.

Merging sites

If you have consolidated multiple sites under one domain, you can redirect all old website addresses to the new domain to streamline the user experience and avoid confusion.

Fixing canonical issues

A “canonical” URL is the preferred version of a webpage that search engines should index. If you have duplicate content across multiple domains, it can create confusion for search engines and hurt your SEO ranking. Redirecting one domain to the other helps establish the correct canonical URL.

Handling expired domains

If an old domain has expired, but you still want to capture any remaining traffic from it, you can redirect it to a new, active domain. 


Step-by-Step Guide to Redirecting a Domain

In the following sections, we will explore how to redirect a domain to another domain through multiple methods. 

Using Domains → Redirects in cPanel

Follow these steps:

  1. Log in to your cPanel account. You can typically access it by going to yourdomain.com/cpanel.
  2. Once you’re logged in, scroll down to the “Domains” section and click the “Redirects” icon.
Redirects location in cPanel
  1. Here, you’ll be able to choose the type of redirect you want to set up. Select either a “Permanent (301)” or “Temporary (302)” redirect from the dropdown menu.
Add redirect in cPanel
  1. In the next field, choose the domain that you wish to redirect. You can also choose the ** All Public Domains ** option if you want to redirect all your domains.
  2. (Optional) If you only want to redirect a specific page or folder within the domain, enter the path after the forward slash (/) in the next box. For example, if you want to redirect “/products” to a new location, enter “products” in this field. Otherwise, if you want to redirect all pages, leave this box empty.
  3. In the “Redirects to” field, enter the full URL of the domain or page where you want to redirect traffic. Ensure you include the https:// prefix.
  4. Finally, select the redirection option based on your needs:
    • Only redirect with www: Will only redirect if the original URL includes www. For example, www.yourdomain.com will redirect, but yourdomain.com will not.

    • Redirect with or without www: Redirects both versions of your domain, with or without www, to the new URL. For example, both www.yourdomain.com and yourdomain.com will redirect.

    • Do Not Redirect www: Redirects only if the original URL does not include www

    • Wild Card Redirect: Redirects all files within a directory to the same file names in the new directory. For example, yourdomain.com/folder/file.html will redirect to newdomain.com/folder/file.html.
Note: It’s important to fully understand your website structure and desired outcome before enabling a wild card redirect. For most cases, it’s recommended to configure a different option.
  1. Double check all the entered details, and then click “Add” to add the redirect.

That’s it. To test that the redirect works correctly, open a web browser and type in the old URL to see if it redirects to the new one.

Using DNS Records

We can also achieve a domain-level redirect by pointing a domain to a web server that’s configured to handle the redirect. Here’s how to go about it:

  1. Log in to your cPanel account. You can typically access it by going to yourdomain.com/cpanel.
  2. Once you’re logged in, scroll down to the “Domains” section and click the “Zone Editor” icon.
Zone editor location in cPanel
  1. Click “Manage” for your domain name.
Edit a DNS zone
  1. Click “Add Record” and then fill out the required details.
  • Name: Enter your old domain name here. 
  • TTL: Keep it at the default value of 14400 seconds.
  • Type: Choose CNAME.
  • Record: Enter the destination address here.
CNAME record in cPanel
  1. Select “Save Record” after double checking for any typos/errors.

It may take some time for the DNS changes to propagate. You can use online tools like DNS Checker to check the propagation status.

Using WordPress

If you are using a CMS, like WordPress, you can set up domain redirection with the help of a plugin. Here are the steps to do so:

  1. Access the WordPress login page (typically at yourdomain.com/wp-admin) and enter your username and password to log in.
  2. From the dashboard, choose “Plugins → Add New Plugin
  3. In the search bar, enter “301 Redirects”. From the search results, spot the “301 Redirects – Easy Redirect Manager” plugin by “WebFactory Ltd” and click “Install Now”.
  4. Give the installation a few moments to complete, and then click “Activate”. This should take you to the installed plugins page.
  5. Click “Manage Redirects” under “301 Redirects”.
301 Redirect plugin in WordPress
  1. Choose the type of redirect from the ID dropdown, and enter the target domain under the “Redirect To” section. 
Adding a redirect
  1. Click “Save”.

That should do it. Open a new browser tab and type in the old URL to see if it redirects to the new URL as expected.

Using the .htaccess file

For granular control over domain redirects, you can edit your website’s .htaccess file. However, this method requires some technical knowledge and caution. A single mistake in your .htaccess file can lead to unexpected behavior on your website, so proceed with care.  

If you’re not comfortable editing code, we recommend using one of the aforementioned methods. With that said, here’s a breakdown of the steps involved:

  1. Log in to your cPanel account. You can typically access it by going to yourdomain.com/cpanel.
  2. Once you’re logged in, scroll down to the “Files” section and click the “File manager” icon.
File Manager location in cPanel
  1. Click “Settings” from the top right, and check the “Show hidden files (dotfiles)” box and save.
Show hidden files
  1. Click the “public_html” folder from the menu on the left. You should see the .htaccess file in this directory.
Public HTML folder in cPanel
  1. Before making any changes, download your current .htaccess file. This will allow you to revert to the original if something goes wrong. To download, hover your cursor over the file name, right click, and select “Download”.
  2. After backing up, right click the file again and select “Edit”. 
Download htaccess
  1. You will now be taken to a separate window with the file open in an editor. 
Edit htaccess
  1. You can add the redirect rule here using the following format:
RewriteEngine On
RewriteRule ^old-page/$ https://www.newdomain.com/new-page/ [R=301,L]

Where:

  • RewriteEngine On: Enables the rewriting engine.
  • ^old-page/$: Defines the old URL path or pattern to match.
  • https://www.newdomain.com/new-page/: Specifies the target URL where traffic should be redirected.
  • [R=301,L]: Flags that indicate a permanent (301) redirect and that it’s the last rule to apply.
  1. Once you have added the required code, click “Save changes” from the top right. 

That should do it. Open a web browser and type in the old URL (https://yourdomain.com/old-page/) to see if it redirects to the new URL (https://www.newdomain.com/new-page/).


Testing and Verifying the Redirect

There are several tools, besides your browser’s address tab, that you can use to verify a domain redirect. Here are some examples:

  • Redirect checker tools: These tools help you check whether your redirect is functioning as intended:
    Small SEO Toolz
    Redirect Checker
  • Developer tools: Open your web browser (Chrome, Firefox, Safari, etc.) and press F12 to open Developer Tools. Go to the “Network” tab, enter the old URL in the address bar, and press Enter. You should be able to see the HTTP status code (301 or 302) in the “Headers” section under “Response Headers“.
  • The curl utility: curl is a command-line utility for HTTP that can also be used for checking redirects. Open a terminal and enter the curl command with the -I option, followed by the old URL. For example:
curl -I https://yourdomain.com/old-page/

In the response, you should see the HTTP headers, including the status code (e.g. 301, 302).


Troubleshooting Redirect Issues

If your redirect isn’t working as expected, here are some steps to troubleshoot:

  • Ensure that your redirect rules are correctly formatted in the .htaccess file or server configuration.
  • Sometimes, browsers cache redirects, which may lead to incorrect behavior. Clear your browser’s cache and cookies, then retry the redirect.
  • If using DNS-based redirects, ensure that the DNS records are correctly configured to point to the desired destination server or IP address.
  • Redirect behavior may vary between browsers and devices. Test redirects on multiple browsers (Chrome, Firefox, Safari, etc.) and devices (desktop, mobile).
  • Check server access logs. Look for entries related to the old and new URLs to verify if redirects are being handled as expected.
  • Make sure that the redirects do not create chains (multiple redirects in sequence). Chains can impact page load times and SEO performance.
  • If nothing else works, contact the support team of your web hosting provider for assistance. 

SEO Best Practices for Domain Redirection

SEO is an important factor to consider when redirecting domains. You want to ensure that search engines understand the move and transfer any SEO value associated with your old domain to the new one. Here are some tips to remember:

  • Always opt for 301 redirects (permanent redirects) when moving a domain. This clearly signals to search engines that the old domain has permanently moved and that they should update their records accordingly.
  • Ensure that the destination URL of your redirect is relevant to the old URL. If you redirect to unrelated or irrelevant content, that can confuse users and harm your SEO efforts.
  • Avoid redirect chains. A redirect chain occurs when you redirect from one URL to another, which then redirects to a final destination. This can slow down loading times and even confuse search engines. Aim for a single 301 redirect from the old domain directly to the new one.
  • Update your XML sitemap to include the new URLs, and submit it to search engines (e.g., Google Search Console) to expedite the indexing process.
  • Use tools like Google Search Console to monitor crawl errors related to redirects. If you spot any, such as 404 errors, address them promptly.
  • Use wildcard redirects sparingly and with caution, as they can inadvertently redirect unintended URLs and disrupt SEO.
  • Keep an eye on your website’s search engine rankings after the redirect. A temporary fluctuation is okay, but over time, your rankings should eventually stabilize or even improve.  

Conclusion

In this post, we discussed how to redirect a domain to a website using different methods. By understanding all the options – cPanel, WordPress plugins, and .htaccess editing – you can choose the approach that best suits your technical expertise and project requirements. Remember to adhere to the aforementioned best practices and recommended steps to ensure a seamless and fruitful transition. 


The Author

Maab S.

Maab is an experienced software engineer who specializes in explaining technical topics to a wider audience.

More posts from Maab