Access options:

New web site is in beta: websemantics.uk. A far better experience.

Redirect scripts

author: mike foskett incept: 19th May 2009

last update: 2nd February 2010

A collection of permanent redirect scripts in various languages.

(X)HTML version

Uses a meta refresh URL redirect:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Redirecting</title>
  <meta http-equiv="refresh" content="0;url=http://websemantics.co.uk/">
</head>
<body>
</body>
</html>

The problem with this is that it isn't search engine friendly and the back button is broken.

Personally I'd add actual content to this page. Well at least a h1 heading and a paragraph explaining the page has moved and a link where to.


<h1>Page has moved</h1>
<p>
	It now resides here:
	<a href="http://websemantics.co.uk/">
		Page title
	</a>
</p>

Javascript version

In Javascript the best method is to use the location replace as it doesn't break the back button:


location.replace('http://websemantics.co.uk/');

Again the problem is that it isn't search engine friendly.

PHP version

The use of a 301 response in the header


<?php
  header( "HTTP/1.1 301 Moved Permanently" );
  header( "Location: http://websemantics.co.uk/" );
?>

ASP version


<%@ Language=VBScript %>
<%
  Response.Status = "301 Moved Permanently"
  Response.AddHeader "Location", "http://websemantics.co.uk/"
%>

ASPX (.net) version


 <%@ Page Language = "C#" %>
 <script runat = "server">
    private void Page_Load ( object sender, System.EventArgs e ) {
      Response.Status = "301 Moved Permanently";
      Response.AddHeader("Location","http://websemantics.co.uk/");
    }
  </script>

If you have any alternate redirects, especially in other laguages, why not email me or post them below for inclusion?

Have your say…

1

Dan

02 12 2009

Can I use

header("HTTP/1.1 307 Temporary Redirect");

or not?

2

mike foskett replies:

16 12 2009

Sorry Dan.
It should of read Permanant Redirects. I've amended the content.
As to the temporary redirect? Usable but not recommended for permanant redirection.

3

EPL Betting

14 09 2010

I've always stuck with php 301's when I've needed a script for that - as you mention the seo component is lacking with many others. But I was wondering, why not include a Perl script in this post too?

Something along these lines I'd imagine:

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

4

How to

20 09 2010

I utilize my .htaccess and always do 301 redirects. Is there a way that the page a user is redirected to keeps the same page title. Is it considered cloaking and will I be penalized by SE if I use this? I need an expert opinion as this is very important to me...thanks in advance

5

mike foskett replies:

27 09 2010

Thanks for the Perl script alternative.
I cannot check it but will leave it in the comments for others to see.

JavaScript redirection could possibly be interpreted as cloaking, but it's incredibly unlikely.

Say what?

Links currently disabled due to spam abuse.
Will reinstate at a later date using Ajax to remove any SEO benefits from posts.

The commenting system used here is a modified version of comment_rave.

Site search & complementary navigation:

Site search:

Online tools

Most popular

New to site