301 Redirect at File Level

From Hostek.com Wiki
Jump to: navigation, search

The 301 status code means that a page has permanently moved to a new location.

You can do a site wide 301 redirect, or you can do a page by page 301 redirect at the page level. Here are the ways to do that:

.htm or .html 301 Redirects

Put this line in your 'head' section

<meta http-equiv="refresh" content="0; url=http://www.your_domain.com/new_page.html">

.asp 301 Redirects

<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.your_domain.com/new_page.asp"
Response.End
%>

ASP.NET 301 Redirects

private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.your_domain.com/new_page.aspx");
Response.End();
}

.cfm 301 Redirects

<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="http://www.your_domain.com/new_page.cfm">
<cfabort>

.php 301 Redirects

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.your_domain.com/new_page.php");
exit();
?>