Redirect a Web Page

This article will guide you through the procedure of redirecting a web page properly, the search engine friendly way with HTTP 301 status in order to tell search engines that the page has permanently moved to a different location.

A while back, a client approached me in order to help her change the name of her business website. This consisted of changing the name on the logo, banners and other parts of the site. Additionally, she purchased a new domain name with several different TLDs. I immediately made the suggestion that we should redirect all the other domains to the .COM domain so that multiple domains could “run” on the same application.

Why not META refresh?

I started off the redirect with the META refresh method and realized that it wouldn’t be search engine friendly because of the fact that a page with a META refresh already has an HTTP 200 status and search engines wouldn’t be notified that the page has moved permanently. So META refresh is not the best proposition! But in case you wondered what it looked like, I made an example below. This code would go into the HEAD section of the page.

<meta http-equiv="refresh" content="0; http://www.domain.com" />

The code above will refresh to the specified URL immediately. You could change the “0″ to the number of seconds the page should wait before instructing the browser to redirect to the specified URL.

Doing it the search engine friendly way!

The proper way to redirect a web page is to use an HTTP 301 status header, telling the search engine bots/spiders that the page has moved permanently to a new location specified. You can do URL redirection in several different languages and methods. Below are several web page redirection examples.

Coldfusion Redirect

<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.domain.com">

PHP Redirect

<?php

header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.domain.com");

?>

ASP Redirect

<%@ Language=VBScript %>
<%

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/"

%>

ASP.NET Redirect

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

Java Redirect

<%

response.setStatus(301);
response.setHeader("Location", "http://www.domain.com/");
response.setHeader("Connection", "close");

%>

PERL Redirect

$r = new CGI;
print $r -> redirect("http://www.domain.com/");

Ruby On Rails Redirect

def old_action
    headers["Status"] = "301 Moved Permanently"
    redirect_to "http://www.domain.com/"
end
  • http://www.homesaleschinohills.com David Hood

    Question 301 redirect are you using this within a domain? If you redirect from a site that is not relevant too you new site how will Google view that?

  • http://www.reverbstudios.ie Leon

    You forgot the .htaccess redirect!?

  • http://www.zorgjuf.nl Hieronimus

    Great articles & Nice a site.

  • http://www.coronahomesforsale.com Corona Homes

    The proper way to redirect a web page is to use an HTTP 301 status header,I agree but it should be used to redirect because a page has been permanently removed.