How To Create 301 URL Redirection?

by S.Pradeep Kumar on May 29, 2009





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/">



Related Articles From This Blog :



{ 1 trackback }

Vote on this article at blogengage.com
December 12, 2009 at 5:48 pm

{ 42 comments… read them below or add one }

1 Anish K.S May 30, 2009 at 1:11 am

Thanks Pradeep, i will check it. the PHP Redirect, i will contact you for assistance. :)

Reply

2 S.Pradeep Kumar May 30, 2009 at 9:23 am

I’m always Happy 2 Help buddy ! :)

Contact me anytime… ! Cheers !

Reply

3 w.Rana July 23, 2009 at 12:20 pm

This is very interesting mate, but I have a question regarding the 301 redirect:
Is it possible to actually totally remove it? I created an index.php file with 301 redirect code in it for a website, but then later on needed to remove it, and I’ve been trying to do so by deleting the index.php file and also adding a new file without any success..is there any way of totally stopping/removing the redirecting of the site?

I’ll appreciate if you can reply :)

Thank you

Reply

4 S.Pradeep Kumar July 23, 2009 at 8:01 pm

Buddy may I know what type of Redirect code you used ? PHP ? HTML ? ;)

Cheers !

Reply

5 w.Rana July 24, 2009 at 11:39 am

thnx for the reply mate, it was a php redirect – like the one you’ve got in your list above.

cheers!

W.R

Reply

6 Nihar May 30, 2009 at 10:36 am

Great thanks for this tutorial. I didn’t know about this.

Reply

7 S.Pradeep Kumar May 30, 2009 at 10:40 am

Hey. Thanks for your comment Nihar !

I’m learning some codings now-a-days . So I tried my hands on posts like these ! :D

Reply

8 Anish K.S May 30, 2009 at 11:15 pm

I need to redirect for only Page not found cases, can please tell how to set it ?.

Reply

9 S.Pradeep Kumar May 31, 2009 at 9:34 am

Create a .htaccess file and paste this code :

ErrorDocument 404 /index.php

And upload it to public_html or htdocs folder of your website ! ;)

Reply

10 Héctor | Blogging Diary June 10, 2009 at 8:57 am

In addition to your post, 301 redirects are specially useful to minimize traffic loss when moving your site to a new domain (as I did a few days ago).

Hey, great theme!! Is this custom-designed? Never seen it before!

Reply

11 S.Pradeep Kumar June 10, 2009 at 11:53 am

Yeah ! One of the main use ! :D

I customized a bit ( little bit ) only !

Theme Name – Revolution (now Studiopress) church ! :)

Reply

12 Héctor | Blogging Diary June 10, 2009 at 2:20 pm

Revolution Church – Now that you mention it, yes it is xD Nice work!

Reply

13 S.Pradeep Kumar June 10, 2009 at 8:57 pm

Thanks Hector ! ..

Glad you liked it ! ;)

Reply

14 JakeI Web Journey June 16, 2009 at 9:10 pm

Very informative post. I have been trying to do this for a while but have been procrastinating. You make it seem easy!

Reply

15 S.Pradeep Kumar June 17, 2009 at 7:01 am

Glad it helped you buddy ! :)

Reply

16 Armawan July 6, 2009 at 11:55 am

It’s good post. But i have problem to redirect 301 for my blog. Can you help me how to redirect 301 from www to become without www. on bloger? (example: redirect 301 http://www.mysite.blogspot.com to http://mysite.blogspot.com)

Reply

17 S.Pradeep Kumar July 10, 2009 at 8:04 am

I added @ the bottom of this post about HTML redirect.. you can try that .. ! ;)

Reply

18 Himanshu July 22, 2009 at 11:06 am

Nice blog and very nice tutorial, seems i will learn lot of things here.Keep writing like this.

Reply

19 S.Pradeep Kumar July 22, 2009 at 12:28 pm

Thanks for the compliment buddy ! ;)

Reply

20 Web Design Chennai July 23, 2009 at 5:49 am

Good comments..i love this

Reply

21 S.Pradeep Kumar July 23, 2009 at 10:11 am

Thanks mate ! ;)

Forming an interactive community here .. thanks for joining ! :D

Reply

22 Web Design Chennai July 30, 2009 at 1:34 am

Hi Pradeep kumar

How to 301 Redirect in Joomla, Please help me…

Reply

23 S.Pradeep Kumar July 30, 2009 at 4:04 am

I’m not that much familiar with Joomla ! but the below steps will work ! ;)

Go to your .htaccess file and paste this code after #Rewrite Base and before the Joomla Core SEF section.

########## Begin - Add www prefix to domain
#
RewriteCond %{HTTP_HOST} ^josephleonwebdesign\.com [NC]
RewriteRule ^(.*)$ http://www.josephleonwebdesign.com/$1 [R=301,L]
#
########## End - Add www prefix to domain

References :

1. How to Make a 301 Redirect in Joomla (non WWW pages)
2. How To Redirect Old Joomla or Mambo Dynamic URLs with htaccess

Reply

24 S.Pradeep Kumar July 24, 2009 at 1:19 pm

@ w.Rana :It is peculiar to see this type of error buddy ! ;)

Can you give me the link of the sites used for redirection.

And you can also try this.. but I’m not recommending it.. you can use this if you are in urgent situation.. in the PHP redirect code.. use the site to be redirected same as the original site ! :D

It is worth a try buddy ! :)

Reply

25 Class of 2013 July 30, 2009 at 1:43 am

Pradeep Kumar

Good list, Very useful redirect code, one person asked how to redirect joomla?..same issues for me, please help me…

Reply

26 S.Pradeep Kumar July 30, 2009 at 4:10 am

Buddy. I’m not that much familiar with Joomla, but I used to experiment with .htaccess ! ;)

Check the comment I made to Web Design Chennai for solution ! ;)

Reply

27 Sarang Dravid August 12, 2009 at 5:24 pm

Hey Pradeep! nice and complete post regarding the topic! inspite to help! I remember there’s a plugin for wordpress direction for permanent 301 url redirection wid name Link juice keeper i guess!!
search bout it for more info ^_^ …

Reply

28 S.Pradeep Kumar August 12, 2009 at 7:34 pm

Hey thanks for sharing that Sarang ! ;)

Even though I’m a plugin minimalist, I’ll try this plugin ! :lol:

Reply

29 Millionaire Acts September 20, 2009 at 1:59 pm

Wow! Your blog site is very much helpful for not techy guys like me. I think I shall visit this more often. No wonder your blog became popular with a fast rising alexa rank of 136K. Congrats!

Reply

30 S.Pradeep Kumar September 20, 2009 at 9:20 pm

Follow on Twitter Follow @HellBlog on Twitter.



Thanks for the kind words buddy ! ;)

Glad to have you in this community ! :)

Stay Connected ! ..

Reply

31 Rajesh Kanuri October 16, 2009 at 1:16 pm

looking for the similar article.. kudos…

Reply

32 S.Pradeep Kumar October 16, 2009 at 1:30 pm

Follow on Twitter Follow @HellBlog on Twitter.



Glad this article helped you buddy ! ;)

Reply

33 Ruchi November 21, 2009 at 1:53 pm

I was looking for Php Redirect Syntax just trying to learn, and found it here, thanks for sharing the information.

Reply

34 S.Pradeep Kumar November 22, 2009 at 11:38 am

Follow on Twitter Follow @HellBlog on Twitter.



Cool Ruchi..glad you found this article in my blog.. cheers! ;)

Reply

35 Uttoran Sen November 27, 2009 at 7:44 pm

thanks for posting a complete guide on re-direction, very useful. i use the re-direction plugin for wordpress, its an easy and quick way to re-direct pages on the same blog :)

Reply

36 S.Pradeep Kumar November 29, 2009 at 10:07 am

Follow on Twitter Follow @HellBlog on Twitter.



Yup.. but many ppl. also prefer plugins.. but I prefer this only! ;)

Reply

37 Rajesh Kanuri @ TechCats December 13, 2009 at 1:57 am

php redirect is far better when compared to plugins…

Reply

38 Will December 13, 2009 at 5:13 pm

Thanks Pradeep, that’s useful information you’re giving out about redirection
Cheers
Will
P.S: Please enter the BRIANWAVE (#BlogEngage) contest !
http://whatawebsite.org/2009/12/11/brainwave-alexa-ranking-contest/

Reply

39 S.Pradeep Kumar December 13, 2009 at 6:44 pm

Follow on Twitter Follow @HellBlog on Twitter.



Count me in for the contest bro.. :)

Reply

40 aks December 13, 2009 at 5:19 pm

yeah php works far better then any plug in cause plug in is a combination of php and javascript in most of the case.

Reply

41 S.Pradeep Kumar December 13, 2009 at 6:43 pm

Follow on Twitter Follow @HellBlog on Twitter.



Yeah.. for me PHP and HTML works pretty fine.. :)

Reply

42 Senthil Ramesh January 1, 2010 at 12:01 am

Simple and easy Bro. I used it with Wordpress plugin.

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post:

</