Redirecting Websites the Proper Way

Redirecting websites properly

When managing a website, there are times when you have to create a redirect.  A redirect can be as simple as “when a visitor goes to page x, take the visitor to page y” to slightly more complex as “when a visitor visits www.mywebsite.com/page-1 or page-2, take the visitor to www.anotherwebsite.com/page-3.”

Redirect can also have implications on SEO.  If it’s not set up properly, not only will it degrade the user experience, it can also generate 404 page not found error, impacting your SEO ranking.

Let’s look at some common scenarios when redirects are needed:

  • Changing business name & website URL
  • Launching a new website (where domain is different from old website)
  • Changing URL of a page from one to another
  • Consolidating multiple sites to a single site
  • Business acquisition

Your hosting provider may provide you with a tool to create redirects.  For some cases, these tools are good enough.  But when a more advanced redirect is needed, you need to go one-level deeper and directly modify the .htaccess file.  For example, if you are redirecting an entire site to another site, you have to create a redirect for each page.  If not, some pages will redirect and some will still serve the old site.

The .htaccess is a configuration file that’s part of Apache Web Server (software powering your websites) that, when placed on a web server, tells Apache to take certain actions.  One of the actions available is redirect.  The tools provided by your hosting provider for creating redirects convert your redirect creation request and updates the .htaccess file.  Because the tools are designed to be simple for anyone without technical background to use, they often lack greater flexibility and thus .htaccess file must be modified directly.

Below is a sample .htaccess file:

It basically says that for any visitors coming to olddomain.com or www.olddomain.com, redirect them to www.newdomain.com.  301 on the last line indicates that this redirect is permanent rather than temporary (302).  In most cases, 301 is what you need – 302 is very rarely used.

How Redirect Impacts SEO

Let’s say you decided you are not providing service B anymore.  You update your service overview page and take out a paragraph that talks about service B and also delete the service B page.  Because there may be links pointing to service B page from another page on your website, external sites, and/or search engines, you may still be getting traffic coming to service B page.  When search engines try to crawl the service B page for an update next time, it will encounter 404 Page Not Found error.  From SEO perspective, 404 error is not good and search engines like Google will look at it as you’re not taking a good care of your website, thereby lowering your SEO scores.

Next, let’s take a closer look at two common scenarios when a redirect is needed and what .htaccess should look like for each scenario.

Business Name Change – Same Website

If you change your business name and your website is now on a new domain, then you need to create a redirect from old domain to new domain.

If everything about your website remains same such as content and the only thing that changed is domain, then you should create a redirect for the entire site and also page-to-page redirect.  For example, redirects should look like following:

Because your old site and all its pages are likely indexed with search engines, it is likely that Google may be serving www.olddomain.com/about-us from its search pages.  So instead of redirecting that to www.newdomain.com, a better user experience would be to redirect to www.newdomain.com/about-us, maintaining same URI.  In that way, the visitor would still see the page they were expecting to see, but on the new domain.

For this, your .htaccss file would look like following:

Business Name Change – New Website

If your domain changes and you have a brand new website with new URLs for your pages, then the best thing is to redirect everything to the root of new domain.  This would look like following:

This is because if /blog/post1 does not exist on the new site, it would generate a 404 error which is not good.  In this case, your .htaccess should look like following:

The only difference is $1 at the end of line on 4th line.  By taking it out, you are redirecting visitors to the root domain.

Consolidating Multiple Sites

This happens from time to time as well.  You are managing multiple websites for your business and decide to consolidate all the traffic to a single website.  You want to do following:

Because it’s most likely that the other sites will not have same pages and structure as the main site, the best would be to redirect to the root of your main site.  The .htaccess file would look similar to the one for “Business Name Change – New Website” but it needs to be created for each site.

Domain1.com

Domain2.com

Domain3.com

Post Actions to Take after Creating Redirects

Because redirects can be lost – for example, when you migrate to a new hosting provider – you need to ensure that any websites or pages referencing old site or old pages are updated with new URL.

Do not take down or delete the old URL right away.  Leave it there for visitors or search engine crawlers to be redirect for some time.

Also, Google will update its index over period of time but if you want your changes to be reflected in search indexes right away, you can use Google Webmasters tool to submit an updated sitemap.  This applies to Bing and Yahoo search engines as well.

If you have any other redirect needs that do not meet the three cases explained above, you can take a look at here for different types of .htaccess configurations.  If you have any questions, please feel free to contact me or leave comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *