SEO Friendly 301 Redirects

February 3rd, 2008 by Jonny Thompson

Page redirection can be accomplished very easily and can be well received by users. In order to best satisfy the needs of search engines a 301 redirection is the optimal way to redirect pages across your website. A 301 status code means “moved permanently” and can be accomplished very easily with some slight variations between coding platforms. Ideally, you will want to focus more on the server side redirects. Client side redirects are prone to issues if users or search engine spiders can’t read javascript.

HTML Redirect

<html>
<head>
<title>301 Moved Permanently</title>
<meta http-equiv=”refresh” content=”4;url=http://www.yakiji.com/newpage.html”>
</head>
<body>
<h1>301 Moved Permanently</h1>
This page has moved. You will be automatically redirected to its new location in 4 seconds.
If you aren’t forwarded to the new page,
<a href=”http://www.yakiji.com/newpage.html”>http://www.yakiji.com/newpage.html</a>.
</body>
</html>

ASP Redirect

<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”;
Response.AddHeader(”Location”,”http://www.yakiji.com/newpage.html”);
Response.End
%>

ASP.NET Redirect (without tracking)

<%@ Page language=”c#” %>
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e) {
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”, Link);
}
</script>

ASP.NET Redirect (with tracking)

<%@ Page language=”c#” %>
<script runat=”server”>
private string Link = “/newpage.aspx”;
private void Page_Load(object sender, System.EventArgs e) {
lb01.Text = “This page may be found at <a href=’” + Link + “‘>” + Link + “</a>”;
}

protected void FinSet() {
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”, Link);
}
</script>
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<script src=”http://www.google-analytics.com/urchin.js” type=”text/javascript”></script>
<script type=”text/javascript”>_uacct = “UA-XXXXXX-X”;urchinTracker();</script>
<h1>301 Moved Permanently</h1>
<form id=”Form1″ method=”post” runat=”server”>
<asp:Label ID=”lb01″ Runat=”server” />
<% FinSet(); %>
</form>
</body>
</html>

IIS Redirect

  • In IIS, right click the file or folder and select properties
  • In the Directory tab, selec the “A redirection to URL” radio button
  • Enter the URL to the location of the redirect in the “Redirect to” textbox
  • Selection “A permanent redirection for this resource” checkbox
  • Click “Apply”

PHP Redirect

<?php
header( “HTTP/1.1 301 Moved Permanently” );
header( “Location: http://www.yakiji.com/newpage.html” );
exit();
?>

htaccess Redirect

  • Create an .htaccess file in your root directory
  • Place the following code in the file

RewriteEngine on
Redirect 301 /oldpage.html http://www.yakiji.com/newpage.php

Javascript Redirect

<html>
<head><title>301 Moved Permanently</title>/head>
<body>
<h1>301 Moved Permanently</h1>
<p>Moved to <a href=”/newpage.php”>http://www.yakiji.com/newpage.php</a></p>
<p>Please change your bookmark or notify the page that linked. Thanks!</p>
<script language=”javascript” type=”text/javascript”>
window.location.href=’http://www.yakiji.com/newpage.php’;
</script>
</body>
</html>

Coldfusion Redirect

<cfheader statuscode=”301″ statustext=”Moved Permanently”>
<cfheader name=”Location” value=”http://www.yakiji.com/newpage.html”>

Ruby on Rails Redirect

def old_action
headers[”Status”] = “301 Moved Permanently”
redirect_to “http://www.yakiji.com/newpage.html”
end

Perl Redirect

#! /usr/bin/perl
use cgi;
my $q = cgi->new();
print $q->redirect(
-location => ‘http://www.yakiji.com/newpage.html’,
-status => 301,
);

Useful Links

Posted in SEO Tips

One Response

  1. System Development

    nice article. this could really help greatly especially for people who needs traffic in their site. appreciate the help thanks.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.