HOW TO: Create 301 URL Redirection

URL redirection is also called URL forwarding, URL shortener, domain redirection and domain forwarding.

Why to redirect a website?

For Similar Domain Names :

301 RedirectionA user accessing a particular domain name may type the wrong spelling of it. For example, consider www.hellboundbloggers.com and www.helboundbloggers.com. Here one ‘l’ is missing in the second domain name. Organizations often register these mis-spelled and redirect them to the correct domain name. Another example is redirecting domains for reserving TLDs (Top Level Domains). The addresses hellboundbloggers.com and hellboundbloggers.net could both redirect to a single domain, such as hellboundbloggers.org.

MUST READ : Introduction To HTACCESS For Newbies

Moving a website to a new domain :

A webpage or website can be redirected for many reasons like the website might need to change its domain name or the author of that website might move his or her pages to a new domain.

HTTP Status codes for redirect :

  • 300 Multiple Choices  (like offering different languages)
  • 301 Moved Permanently
  • 302 Found (like temporary redirect)
  • 303 See Other (For results of CGI-Scripts)
  • 307 Temporary Redirect

Common Methods for Redirecting A Website [URL Redirection]

Open Notepad or any other editor and copy the required code and save it. Then upload that file to your directory. I made use of the PHP redirect for redirecting My Mobile Site to Google Reader. I made mobile version of my blog through Google Reader.

ColdFusion Redirect

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


PHP Redirect

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>


ASP Redirect

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.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.new-url.com");
}
</script>


JSP (Java) Redirect

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>


.htaccess Redirect

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]


CGI PERL Redirect


$q = new CGI;
print $q-&amp;gt;redirect(&amp;quot;http://www.new-url.com/&amp;quot;);


Ruby on Rails Redirect

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end


HTML Redirect

Place the following HTML code between the <HEAD> and </HEAD> tags of your HTML code.

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yoursite.com/">