The 301 Redirect and Why I Need One

Posted on October 13, 2008 at 11:17 pm.

The 301 redirect solves many problems that are associated with websites that have changed servers or changed hosting companies. The 301 redirect will … redirect… the incoming traffic to the specified web address. Pretty simple, one file takes care of the entire site however, that is not why I’ve called you here. One of the more subtle uses for the 301 redirect is to solve a not so well known SEO issue. The 301 redirect I show here is for this specific purpose.

Apache, the server software, has a setting to ignore the www part of a URL. This way someone can just type in http://domainname.com and it will go to the same site as http://www.domainname.com. Now days’ having this setting off is standard procedure for all server software. Cool. No, not cool, because Google and other search engines will see these as two different websites. If you have in-bound links pointing to both the www and the non-www versions you’re getting ripped off because Google thinks they are two different websites and only gives credit for the in-bound links that are specific to each.
In-bound links are considered Google Gold; if you have 10 backlinks pointing to the www version and 10 pointing to the non-www version you’re robbing yourself of 10 backlinks, twice.

The 301 redirect solves this by pointing one to the other, at the server level, and the search engines respect this.

Create a text file with the below code, name it .htaccess then post it to your root directory (the same directory where your index file is placed). This will ensure that all your directories and pages get correctly redirected. If there is already an .htaccess file in this directory, upload it, and add the code somewhere on its own lines.

The following routes all www URLS to the non-www URL.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

or this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

or this:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE www.newdomain.com in the above code with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.


IIS Redirect (Windows Servers)

* In internet services manager, right click on the file or folder you wish to redirect
* Select the radio titled “a redirection to a URL”.
* Enter the redirection page
* Check “The exact url entered above” and the “A permanent redirection for this resource”
* Click on ‘Apply’

NOTE TO WORDPRESS USERS:

WordPress has a built-in function that works just like a 301 redirect. In your settings under General Settings you can set your preference by entering the preferred URL here, www or no-www. No need for the .htaccess file.

CAUTION; if your blog is in a sub-folder and you need a 301 redirect for your root directory, be sure the General Settings address in WordPress is the same as the one specified in the .htaccess. If they are different, when you browse to your blog you’ll get an unresolved link error as .htaccess sends the browser to www then WordPress sends it back to no-www, .htaccess to www, WP to no-www, back and forth add infinitum.

Bookmark and Share

Tags ,


Leave a Reply