Search Ben Acheson's Blog

Thursday, 2 September 2010

301 Redirects for SEO

301 Redirects for Search Engine Optimisation

A 301 redirect (permanent server redirect) is used to redirect visitors from one URL to another on a permanent basis. You are about to learn how to implement it. The 301 redirect is an important tool for SEO (search engine optimisation) and online marketing generally, for a number of reasons:

1) If there are valuable inbound links, the Pagerank, link value, link equity or link juice built up for the old page will be passed to the new page so it enjoys the same level of importance or authority in search engine results. (It can take a while for Pagerank to pass to the new page so plan ahead).

2) People following existing inbound links from other websites will automatically be redirected to the new page. People finding your page through a search engine will also be redirected to the new page.

3) Users may visit an old URL directly because they remember it, or because it is in their favourites or browsing history.

4) A 301 redirect can also be used to shorten all your URLs sitewide, from to just - this makes your URL quicker to read and easier to remember. It also means less characters are used when posting the URL in Twitter, or anywhere you only have a limited number of characters. If your domain starts with a relevant keyword, dropping the unnecessary and irrelevant 'www.' may be even more beneficial for SEO.

First, find out if your website is hosted on Microsoft or Apache server. enter your domain name (e.g. '') into this free lookup tool:

The response for 'Server' will start with 'Apache' or 'Microsoft' (and then some more information about the system which you don't need).

Apache server 301 redirect using .htaccess file

If your website is hosted on an Apache server then 301 redirects are very easy to implement using a .htaccess file.
Download a sample .htaccess file here. (It is important that your file name starts with a '.' and does not have a hidden file extension such as '.txt', so it's easier just to download this example).

Edit the .htaccess file (right-click, open with, notepad...) then save it and upload it to the root directory of your website. This is the place where your index page (index.html for example) is stored. It may be a folder called 'public_html' within your FTP site and is the highest level where files can be accessed online.

Apache .htaccess 301 redirect old page to new page:

Paste the following text into your .htaccess and amend it for your domain, old page and new page URLs. Then upload it into your website's root directory.

Redirect 301 /oldpage.html

Apache .htaccess 301 redirect your entire website:

Redirect 301 /

Apache .htaccess 301 redirect your entire website from www to non-www URL:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*)$1 [R=301,L]

Apache .htaccess 301 redirect your entire website (domain and all pages) from non-www to www URL:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

Microsoft Windows hosted / ASP websites

A 301 redirect on Microsoft is much more complex. The easiest solution - especially if you need to redirect a lot of pages - is to install
Isapi Rewrite on your server:

You can then set up an ISAPI Rewrite filter with a few lines in your httpd.ini file:

Microsoft Windows Server IIS tweak:

Alternatively you could ask your hosting provider to set up a
301 redirect by modifying IIS:

Other 301 redirect methods:

1) code 301 redirect on each page

Add the following code to all the ASP pages on your website:

Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
if domain_name <> "" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "" & HTTP_PATH
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
end if

Better still, save this code in a file named '301redirect.asp' and then add the following snippet at the top of each file on your site:
<!-- #Include file="301redirect.asp" -->

2) VB script 301 redirect on each page:
<%@ Language=VBScript %>

3) 301 redirect using code on each page:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
Response.Status = "301 Moved Permanently";

4) Ruby on Rails 301 redirect using RoR code on each page:

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to ""


Christian Gabriel C. said...

I am currently using this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
It works fine (partially). If I want to go to and be redirected tot he exact same page on the www version, it does NOT happen. I get redirected to the home page of the www version. Is there a ONE script which would arrange a proper redirection from old pages (non www) to new page(www) (ideally without having to add a redirection line for each new page I create)? many thanks.

Ben Acheson said...

Hi Christian,

For sitewide non-www to www 301 redirect:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

Christian Gabriel C. said...

yay :) .. this one finally did it. VERY many thanks.