Creation date:

redirect 301

We need page redirection from time to time. Especially when you move the content to new domain. Because some usefull pages are indexed by search engines and you don't want to lose clients bookmarking these pages.

mod_rewrite Redirect

With this rule we redirect the page old.php to the new.php. Write the following instruction in .htaccess file. Note, that R=301 means redirect permanently and instructs search engines to update their record regarding old.php. If you don't want to redirect permanently use 302 code unstead of 301. The 302 code tells clients to not cache the result because the resource is temporarily moved.

RewriteRule ^old\.php$ /new.php [R=301,L]

Look this table for the meanings of other codes. Although 302 is named "Found" the meaning of code is temporarily moved.

Status Code Description
300 Multiple choices
301 Moved permanently
302 Found
303 See other
304 Not modified
305 Use Proxy
307 Temporary Redirect

PHP Redirect

In this method we modify the header of page with PHP header() function

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

HTML meta tag Redirect

It will redirect the page to in ten seconds

<meta http-equiv=refresh content=10; url=>

JavaScript Redirection

Because JavaScript is executed on client site it's least reliable method and depends on parameter of browser. Especially in IE you may get unexpected behaviour.

<script type="text/javascript">"", "_top")

IIS (Internet Information services) Redirect

ColdFusion Redirect

<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="">

ASP Redirect

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

ASP .NET Redirect

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
Response.Status = "301 Moved Permanently";

JSP (Java Server Pages) Redirect

response.setHeader( "Location", "" );
response.setHeader( "Connection", "close" );

CGI PERL Redirect

$q = new CGI;
print $q->redirect("");

Ruby on Rails Redirect

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to ""

Author: Jafar N.Aliyev (Jsoft). Some methods are got from other sites and not checked by me.

Read also

HTML tips

Here I listed some useful HTML tips

© Copyright

All articles in this site are written by Jafar N.Aliyev. Reproducing of any article must be followed by the author name and link to the site of origin(this site). This site also keeps the same rules relative to the articles of other authors.