301 Redirect


 

The 301 redirection is described in RFC2616: “The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs”.

Browsers automatically follow these redirections. They also display the new permanent address in the address bar.

In accordance with RFC2616, the same address pointed to by the redirection will eventually be saved in the browser favorites.

The standard recommends to use a 301 redirect when a page has been permanently moved to a new address.

301 Redirect and Search Engines

 
According to RFC2616, search engines should forget the redirecting address and save the address pointed to by the redirection as the preferred address.

When a page has been moved to a permanent new address, Google recommends to use a 301 redirect. But, strangely enough, the leading search engine often needs weeks or months to take this information into account in its search results.

301 Redirect Implemented in .htaccess File

 
Assuming the web server allows it, it is easy to implement a 301 redirect in .htaccess.

Moving a page
RedirectPermanent /old-file-name.html http://www.new-domain.com/new-directory/new-file-name.html

Moving a directory
RedirectPermanent /old-directory http://www.new-domain.com/new-directory

Moving an entire site
RedirectPermanent / http://www.new-domain.com/

301 Redirect Implemented in a Server Script

 
The script (typically a PHP, Perl or ASP program) will have to generate a 301 header.

Moving a page in PHP
<?php
header(”Status: 301 Moved Permanently”, false, 301);
header(”Location: http://www.new-domain.com/new-directory/new-file-name.html”);
exit();
?>

Checking if a 301 Redirect Works

 
InternetOfficer has designed a free on-line tool to check the working of redirects. This new tool to check redirects analyses the HTTP-header and the page contents and identifies in seconds 301 and 302 redirects and HTML redirects (meta refresh).

6 Responses to “301 Redirect”

  1. Web Programmer says:

    I started a thread few days ago on the HTTP Error (status) codes at WebMasterWorld and I got some good replies that are worth reading related to your article. Not based on specs but on user experiences.

    http://www.webmasterworld.com/google/3430126.htm

  2. David DeAngelo says:

    I would also like to add that 301 redirect in the .htaccess file can be implemented as follows:

    redirect 301 /old-file-name.html http://www.new-domain.com/new-directory/new-file-name.html

    Apart from this, we could also use rewrite (also sending a 301 status):

    RewriteEngine On
    RewriteRule ^olddir/(.*)$ http://www.new-domain.com/newdir/$1 [R=301,L]

  3. Deck Jamie says:

    is there a way to 301 redirect in iis only with ftp and without any access to the server admin.

  4. Jean-Luc says:

    You can put this code in the pages to be redirected:

    <%@ Language=VBScript %>
    <%
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "http://www.example.com/new_url"
    %>

    or

    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = "301 Moved Permanently" ;
    Response.AddHeader("Location","http://www.example.com/new_url") ;
    }
    </script>

    Jean-Luc

  5. Ong Gia says:

    Hi, the previous webmaster for a site I’m working on had a bunch of files named in French with accents. I renamed those in order to take them out. Unfortunately, google still manages to see the old pages and they lead to a 404 error.

    I’ve created a .htaccess file to redirect quite a few pages but I’m having some issues with those files in particular.

    i.e: I renamed a file previously named “série.pdf” to “serie.pdf”

    Google sees the “série.pdf” as something like this “S%C3%89RIE.pdf” and I think that is where the problem lies…

    My redirect line goes something like this:

    redirect 301 /images/brochures_fr/S%C3%89RIE.pdf
    http://mywebsite.com/redirect/images/brochures_fr/SERIE.pdf

    Unfortunately, it doesn’t seem to work.

    If you could provide me with any input or suggestions, I’d greatly appreciate it.

    Thank you for your time.

    Sincerely,

    Ong Gia

  6. Jean-Luc says:

    Try this:
    redirect 301 /images/brochures_fr/SÉRIE.pdf
    http://mywebsite.com/redirect/images/brochures_fr/SERIE.pdf


 

Leave a Reply