Skip to main content

Web page 301 redirect scripts in HTML, JavaScript, PHP, ASP and

- (incept: )

(X)HTML version

Uses a meta refresh URL redirect:

Language HTML
<!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.

Language HTML
<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:

Language JavaScript

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

PHP version

The use of a 301 response in the header

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

ASP version

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

ASPX (.net) version

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