IT Excuse Generator

Feeds
Add to Google
RSS FEED


February 23, 2007

How To Properly Redirect A Page On A Web Server Using 301

Its best if you can avoid moving things around or changing domain names as it always affects your Page Rank and can also break bookmarks and existing links. But if you're forced to rearrange things around there are some ways you can minimize the damage.

The goal is to generate a 301 redirect message when the page is loaded. This automatically redirects the visitor from the current page or site to another page or site, while returning a technical response code. The code explains to search engines that the original page or site has been permanently moved to the new location and the search engine will then know its ok to transfer the Page Rank to the new site.

If you are using an Apache web server and have access to your .htaccess file and can edit it you may add the following to it to redirect a domain:
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.usrbingeek.com/$1 [L,R=301]

There are lots of other ways too:

PHP Example Code
My favorite method uses PHP but this will only work if the file your moving was a php file. Just change the URL in this example and replace your old file's contents with it:
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.usrbingeek.com/');
exit;
?>

More after the jump....

ASP (VBScript) 301 Redirect Example Code
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.usrbingeek.com/"
response.end
%>

ASP (JScript) 301 Redirect Example Code
function PermanentRedirect(strDestinationUri) {
Response.Clear();
Response.Status = 301;
Response.AddHeader("Location", strDestinationUri);
Response.Flush();
Response.End();
}

Note: "strDestinationUri" should be an absolute URI for maximum client compatibility. The function assumes that "Response.Buffer = true;" has been set at some point prior to invoking the function and will error if hasn't (this is the default configuration for IIS5 and above).

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

Cold Fusion (CFM) 301 Redirect Example Code
Simply add this code to your ColdFusion page:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.usrbingeek.com/">

JAVA/JSP 301 Redirect Example Code
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.usrbingeek.com/" );
response.setHeader( "Connection", "close" );
%>

Perl 301 Redirect Example Code
#! /usr/bin/perl
use cgi;
my $q = cgi->new();
print $q->redirect(
-location => 'http://www.usrbingeek.com/',
-status => 301,
);

Posted in How To & DIY , Web Design by usrbingeek at 2007-02-23 14:43 ET (GMT-5) | 0 Comments | Permalink



Comments










This web site is provided "as is" with no representations or warranties, and confer no rights. We are not liable for omissions or typographical errors contained in the content. Use at your sole risk.
The opinions expressed here do not necessarily represent any other entity or party we may have a connection or affiliation with.
usrbingeek, usr bin geek, usrbingeek.com, #!/usr/bin/geek are trademarks of usrbingeek LLC. All other trademarks and tradenames are property of their respective owners.