Access options:

New web site is in beta: 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" "">
<html xmlns="" xml:lang="en" lang="en">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="refresh" content="0;url=">

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>
	It now resides here:
	<a href="">
		Page title

Javascript version

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


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

PHP version

The use of a 301 response in the header

  header( "HTTP/1.1 301 Moved Permanently" );
  header( "Location:" );

ASP version

<%@ Language=VBScript %>
  Response.Status = "301 Moved Permanently"
  Response.AddHeader "Location", ""

ASPX (.net) version

 <%@ Page Language = "C#" %>
 <script runat = "server">
    private void Page_Load ( object sender, System.EventArgs e ) {
      Response.Status = "301 Moved Permanently";

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

Have your say…



02 12 2009

Can I use

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

or not?


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.


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 => '',
-status => 301,


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


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