Setting up 301 redirects

by Werner deBruin

In SEO, one of the most common errors we come across when looking at new websites is that they are not making use of the correct redirects to address their Canonicalization and URL redirecting issues.
Just to jog your memory quickly – there are 2 types of redirects. The first is a 301 Permanent redirect and the second a 302 Temporary redirect. Although both do the job of redirecting the old URL to its new location, redirects can cause some logistical issues for your SEO campaign.

The 302 Temporary Redirect acts as an indicator to tell the server (or search engine spider) that the redirect is only a temporary one, and that the old URL is still more relevant than the current (temporary) destination.
In the case of a 301 Permanent redirect, the server (or spider) takes note that the old page is no longer relevant and that all the relevance from the old URL should be carried over to the new destination.

Relevance, as we know, is important to search engines and without using a 301 redirect you will not benefit from any of the old domain’s history or inbound links. In one case a new client was complaining about the rankings on his new site. We then discovered that none of his pages on his new domain showed up on Google, only the old domain’s results were showing. We did a bit of investigating and discovered that he used the incorrect 302 temporary redirect which told Google to not worry about the new domain and rather keep the old domain information.

So now that you we know why we should change them to 301’s, but how do we do this?

------------------------------------------------------------------------------------------------------
IIS Redirect:
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'

ColdFusion Redirect:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">

PHP Redirect:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com " );
?>

ASP Redirect:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com/");
%>

ASP .NET Redirect:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>

JSP (Java) Redirect:
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>

CGI PERL Redirect:
$q = new CGI;
print $q->redirect("http://www.new-url.com/");

Ruby on Rails Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

Redirect Old domain to New domain (htaccess redirect):
Create an .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e. the same directory where your index file is placed).

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1  [R=301,L]

Please REPLACE www.newdomain.com in the above code with your actual domain name.
In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect):
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed).

Options +FollowSymlinks
RewriteEngine on
rewritecond %

Unknown macro: {http_host}
^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1  [r=301,nc]

Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
------------------------------------------------------------------------------------------------------

After you have changed your redirects, test to see if they are SEO friendly by typing the old URL below:


Enter the URL whose Redirect you want to check
(Redirect From URL)

2007/11/27 | permalink | comments (13) | trackbacks (0)
Bookmark with del.icio.us Digg It Submit to Reddit muti sphinn  
Visit Brandseye.com  Subscribe to RSS

Comments

post a comment

Great post Werner!

Posted by Janine on 2007/11/28

lekkerbru. hows about a CPanel how to for those other folks...

Posted by Smith on 2007/11/29

Hey Smith. Aren't you able to edit the .htaccess file found on your root directory (public_html in most cases) from CPanel's file manager?

Posted by Rafiq Phillips on 2007/11/29

Ok Smith, I will include that to my to do list for December...

Posted by Werner on 2007/11/30

Thanks Werner, very useful!

For those using an ISAPI filter for URI rewriting, here is how to set up a 301 Moved Permanently rule for http:example.com/ to http:www.example.com/.

RewriteCond Host: ^example\.com
RewriteRule (.*) http\:www\.example\.com$1 [I,RP] //

Just add the rule into your local httpd.ini file.

Posted by Riaan Botha on 2007/12/03

Often Blog posts are full of opinion and very little substance. An entertaining little titbit of information that one can toss aside equally easily. However I must admit that your posts are always informative and substantial. I gave this bit of info to the development team (they are always thrilled to get advice from Legal and Finance on how to do their job so I dutifully oblige). Thanks Werner

Posted by Chewbacca on 2007/12/04

i want Redirect my site place of
http:www.roughguides.co.uk.

co.yk status code 200-ok
this not correct status code i want when this url browser sent 200 status code to server because i have set 301 Permanently status code for http:
www.roughguides.com url . Please help me

Thanks

Posted by Ravi Yadav on 2007/12/12

Great post Werner. I've always understood the value of 301 vs 302, but as a non-technical person have never really known how to implement it correctly.

No more battling with "developers" who keep telling me that a site is redirecting when it's actually just cloned on a different domain. Hurrah!

Thanks.

Posted by Jono on 2007/12/12

I could get the ASP redirect to work: found this page has syntax that worked for me: http://www.seoconsultants.com/tips/asp/301.asp

Cheers

Posted by Dave Lockie on 2008/07/02

I mean I could NOT get the...

Posted by Dave Lockie on 2008/07/02

Hello,
Thanks of lots.

Posted by ravi Yadav on 2008/07/03

thanks Dear ,
hey Dave Lockiecan you join me on gmail
my e-mail id raviyadav2002@gmail.com

Posted by Ravi yadav on 2008/07/03

Name:
E-mail:
Url:
Comments:

Markup guide:

**
makes text bold
**

//
makes text italic
//

--
creates a link
--

(two dashes, no http://)
Remember personal info?
Notify me of follow-up comments?
SPAMCHECK:
 

Quirk eMarketing
Visit our Website

BrandsEye

Subscribe

RSS feed Post feed
RSS feed Comment feed

RSS to Email

Get our latest blog posts delivered straight to your inbox.

 

eMarketing News

Subscribe to our fortnightly newsletter which is packed with interesting eMarketing news, views and other quirky titbits.

September

S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
             

 

Archives

  

Categories

Recent Posts

Recent Comments

  • Claire on The Bear Trap
  • reenasally on Orangina: Animals Behaving Badly
  • SuperSanti on Hello The World
  • Sarah Manners on Orangina: Animals Behaving Badly
  • Kat on Orangina: Animals Behaving Badly

Wannwork@quirk


More photos of the QuirkStars At Play
Quirkstars

Name:
Friends of Quirk
Websites:
www.quirk.biz

Skribit: Social Suggestions

 
Afrigator