Friday, August 25, 2006

Redirects in ASP

Redirecting a user to a new web page or web site is a common task many webmaster will need to accomplish sooner or later. There are some redirects that work better than other, however, when it comes to maintaining search engine position.

I don't recommend using JavaScript or Meta Tag refresh redirects as you can't send a 301 status code with either of these methods. JavaScript and Meta Tag rredirects have long been exploited by less than honest web masters who are trying to game the system. Instead use a server side redirect programmed in ASP.

Most ASP programmers are familiar with:

<%
strURL = "http://www.Google.com"
Response.Redirect(strURL)
%>

Where URL is a variaable contina the location of the new page or site.

This command performs a server-side redirect to the new page, but it returns a Status code of 203, which means "temporarily moved". This tells the search engine that although it is being directed to a new location, that the move is only temporary. Hence the search engine will not remove the old page and replace it with the new one.

You need to tell the search engine spider that the page has move <i>permanently</i>:

<%
strURL = "http://www.Google.com"
Response.Status="301 Moved
Permanently"
Response.AddHeader "Location", strURL"
%>

This would tell the search engine spider that the original page has been "moved permanently" to the new location. Your old page will drop out of hte the results and be replaced with the new. Eventually....

I've never used redirects in other development languages, but here they are if you need them. I've included JavaScript and and Meta Tag refresh methods as well, although I recommend agaisnt using them:

HTTP 301 Redirect in PHP
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved
Permanently");
header("Location: http://www.somacon.com/");
exit();
?>

HTTP 301 Redirect in ColdFusion
<CFHEADER statuscode="301" statustext="Moved Permanently">
<CFHEADER name="Location" value="http://www.somacon.com/">
JavaScript
<html>
<head>
<script
type="text/javascript">
window.location.href='http://www.somacon.com/';
</script>
</head>
<body>
This page has moved to
<a
href="http://somacon.com/">http://somacon.com/</a>
</body>
</html>
Redirection with META Refresh
<html>
<head>
<meta
http-equiv="refresh" content="0;url=http://www.somacon.com/">
</head>
<body>
This page has moved to
<a
href="http://somacon.com/">http://somacon.com/</a>
</body>
</html>

1 comment:

jones said...

Nice blog...
visit also coldfusion example