How to Implement a 301 Redirect
Implementing a 301 redirect or more precisely managing 301 redirects is increasingly an integral part of technical SEO. This is especially the case when websites expand or migrate from one owner, host, domain or code platform. Over time, websites, if not properly managed, tend to get ragged. Duplicate content, broken links and out of date site maps tend to be errors that show up in your Google Search Console Tools or Moz crawl diagnostics summary. Firstly a 301 redirect redirects a browser from an old to a new location. Secondly, and most importantly for SEO, a 301 redirect tells search engines that your web page has been permanently moved to another location or address. As a consequence, the search engines transfer the PageRank, or link juice, from the old location to the new.
Using a CMS for your Redirect
If you utilise a content management system or CMS, there are quite often tools inside that allow you to arrange redirects. Check in your CMS tools section first. If you use WordPress or similar platform you may find a plug-in that will do the redirect. If not, you will have to arrange the redirect yourself, usually via a .htaccess file. In my case, I was working on two separate redirects. One to send http://simplyclicks.com traffic to www.simplyclicks.com. The other to eliminate the index.html versions of my home page. There are good reasons for undertaking both redirects.
Redirecting http://yoursite.com to http://www.yoursite.com
There are two good reasons for implementing this redirect. Firstly, Google may treat the http:// only and the www versions of your site as two different sets of documents. Secondly here is a risk that you will build up two sets of inbound links. There are many ways of organising a redirect and the way selected depends on your operating system and server. In the most recent case, I was organising a redirect on an Apache server utilising Linux.
Redirecting www.yoursite.com/index.html to www.yoursite.com
My main reason for organising this redirect is a problem I have with web analytics. Quite often, web analytics will treat these two versions of the home page as two different pages. So you end up adding and diving all the time to get consolidated statistics for your home page. The second reason is more long term and affects link building. What happens, if people send links to a home page which is www.yoursite.com/index.html and you moved platforms? So that your home page became www.yoursite.com/index.php? Without a redirect, the old page would become a broken link, losing all its link juice or PageRank. This redirect also applies to a redirect of .php or similar. But not .asp as this would be covered by the Microsoft IIS and is not covered here.
The 301 Redirect Code
Below, I show the code used for organising both redirects in the same .htaccess file. The redirects must be in this order. The .htaccess file is uploaded to the root directly of your website that contains your home page.
########
RewriteEngine On
#
# redirect index.htm and index.html to / (do this before non-www to www)
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.yoursite.com/$1 [R=301,L]
#
# redirect domain.com -> www.domain.com
#
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
########
If you use this code you will need to change the “yoursite.com” to your exact domain, e.g. simplyclicks.com in my case. This code works for me on Fasthosts.com, the largest UK hosting provider. You may need to make several tries and depending on your web host wait for the new .htaccess file to become activated.