You are here:

SEO Friendly Permanent Redirects

5.00 out of 5 based on 5 ratings. 1 user reviews.

This tutorial describes how to properly redirect a web page using an HTTP 301 status code and Location header. The 301 status code is used to indicate that a page has permanently moved.



I. Redirects with Server Side Scripting

If you have a dynamically driven (server side) web site, you can implement one or more of the following scripts, depending on which scripting language(s) you use.

These portions of code are fairly self-explanatory. They simply provide the appropriate 301 response header, and the location of the new page.


seo software


HTTP 301 Redirect in ASP-VBScript

Include the following ASP code at the top of each page:
<%@ Language=VBScript %>
<%
' Permanent redirection
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.dexterityunlimited.com/"
Response.End
%>


HTTP 301 Redirect in ColdFusion

Include the following ColdFusion code at the top of each page:
<CFHEADER statuscode="301" statustext="Moved Permanently">
<CFHEADER name="Location" value="http://www.dexterityunlimited.com/">

HTTP 301 Redirect in PHP

Include the following PHP code at the top of each page:
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.dexterityunlimited.com/");
exit();
?>


HTTP 301 Redirect in Perl

Include the following Perl code at the top of each page:
#!/usr/bin/perl -w
use strict;
print "Status: 301 Moved Permanently\n";
print "Location: http://somewhere/page.htm\n\n";
exit;


HTTP 301 Redirect in JSP/Java

Include the following Java code at the top of each page:
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.dexterityunlimited.com/" );
response.setHeader( "Connection", "close" );
%>


II. Redirecting with .htaccess

If you are on an Linux/Apache server, or a Microsoft Windows Server that can run Apache modules, you can do your redirects with an .htaccess file.

The .htaccess file is a very powerful tool, but can wreak havoc on a site if not implemented correctly. Always save a backup of any existing .htaccess file before attempting any changes.


Redirection with mod_rewrite

The following lines redirect the client to a new location. In this case, a request for the file contact.php is sent to the file contact-us.php:

rewriteEngine on
rewriteRule ^contact\.php$ http://www.dexterityunlimited.com/contact-us.php [R=permanent,L]

seo software


Redirect all non-www traffic

The code below will direct all traffic which does not contain the www in the URL to the same page, but now including the www. And that will clean up the canonicalization problem that arises when the www version of your site gets indexed along with the non-www version:

rewriteCond %{HTTP_HOST} ^dexterityunlimited\.com$
rewriteRule ^.*$ http://www.dexterityunlimited.com%{REQUEST_URI} [R=permanent,L]

Redirect aliases of home page to the root website

Have you noticed in your log files that people are looking for index.htm or index.asp in your root folder? Instead of letting them get a 404 Not Found error, why not direct them to your root folder, without a filename:

rewriteRule ^index\.(php|html|htm|asp) http://www.dexterityunlimited.com/ [R=permanent,L]

III. SSL https to http

Have you experienced serious canonicalization problems when the secure https version of your site was fully indexed along side your http version? If that is your case, there is a way to redirect https for the bots, telling them bots not to index the https version.

Our tutorial Search Engine Indexing of Secure Pages describes how to properly implement search engine friendly redirects using an HTTP 301 status code and Location header.


Why should I do this?

I am certain there are some of you asking this question. The answers are many, depending on your particular situation.

Are there links to your site that are outdated, but you have no way to change them? Simply create a redirect that will take visitors using that outdated link to the most appropriate new page on your site.

Is there a link in a directory somewhere that is misspelled, or is missing the www? Use one of the methods above to correct the situation at the server.

There are many ways for you to control what people see and where they can go on your web site. Take some time to learn a few tricks, and you might find that your traffic increases because you aren’t leaving anyone behind.


Disclaimer

All of the snippets of code above are examples and each were tested by us at some point. However, we are in no way responsible for any damage they may cause. You use them at your own risk.


seo software


About this SEO tutorial

This tutorial was written by , Forensic SEO & Social Semantic Web Consultant at SEO Workers and was published June 26, 2007.

Copyright reserved. Not to be reproduced.

Comments & Ratings

Search Engine Friendly Permanent Redirects questionaries 5 stars 2010-07-10 02:40:22 Awesome collection of information! I'm not to technologically savvy but you tell it in English. Thanks very much!


Attention Comment Spammers!

  • Google says that spamming other sites can lower your site rankings;
  • Signature links under comments are not accepted;
  • Highly relevant links in the body such as the web site or blog URL are allowed, but only upon our approval;
  • You can expect that your comment may be deleted if you are attempting to get a backlink link rather than adding real value to the conversation;
  • SEO or Link Builders, if we catch you commenting but linking to a client's site, your online reputation, your firm's and that of your client are being put at severe risk;
  • Link to a page or a blog that can be identified as being about you, so our readers can gain additional perspective on your point of view and where necessary sufficient disclosure.
Comment & Rate