HOW TO: Create 301 URL Redirection

Written by in HTACCESS - Print This Post



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




HBB RSS
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic. You will also get instant access to 100+ HBB Guides & Tutorials.
If you wish to subscribe here via Email, then kindly click here.


Connect with HBB on Facebook Easily




Editor-in-Chief and Owner of 20 Years Old Kiddo, Open Source Enthusiast, Tech Blogger, Striving Entrepreneur, and a Typical Engineering Student. Addicted to Blogging, Walking and Messing. Catch him on Facebook, Twitter and .


HBB has 546+ Awesome Contributors. [Join HBB].

HellBound Bloggers (HBB) is a part of Slashsquare Network.







55 Responses to “HOW TO: Create 301 URL Redirection”

Leave a Reply


Comments Policy | Brand Your Comments | Do Follow Blog | Top Commentators Award


REFERENCE : 7 Tips To Be A Hero On Blog Commenting [HELPFUL]


Overall HellBound Bloggers (HBB) has 22,031 Genuine Comments and Yours Will Add More Value To It.




Previous Article:

Next Article:

  1. Anish K.S says:

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

    • I’m always Happy 2 Help buddy ! :)

      Contact me anytime… ! Cheers !

      • w.Rana says:

        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

  2. Nihar says:

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

  3. Anish K.S says:

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

  4. Héctor | Blogging Diary says:

    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!

  5. JakeI Web Journey says:

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

  6. Armawan says:

    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)

  7. Himanshu says:

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

  8. Good comments..i love this

  9. @ 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 ! :)

  10. Class of 2013 says:

    Pradeep Kumar

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

  11. 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 ^_^ …

  12. 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!

  13. looking for the similar article.. kudos…

  14. Ruchi says:

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

  15. Uttoran Sen says:

    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 :)

  16. Will says:

    Thanks Pradeep, that’s useful information you’re giving out about redirection
    Cheers
    Will
    P.S: Please enter the BRIANWAVE (#BlogEngage) contest !

  17. aks says:

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

  18. Simple and easy Bro. I used it with WordPress plugin.

  19. It’s must for all bloggers to redirect broken page…
    .-= sudharsan @ technoskillonline’s last blog…Win Dell Inspiron Laptop Free – Sizlopedia Contest =-.

  20. Tech Junoon says:

    I believe PHP Redirect is the best and easiest idea.

  21. Saikrishna says:

    Very Easy To Understand And Thanks For The Trick :)
    It Helped Me
    Have A Nice Day…!

  22. Charlie Lapena says:

    It is important to redirect the website to e able to know if there are some problems that had occurred. In this way, the site will be fixed.

  23. sonu says:

    just used htaccess method on a blog. need some tips on using .htpswd and how to block a country using htaccess.

  24. Karan says:

    Well this is an essential feature if you want to move your blog to a new domain without losing the value you have earned to your current blog.

  25. Well, I don’t need it but still… thanks for sharing :D

  26. Nisha Shah says:

    Easy To Understand . Helped me alot. Big thanks for sharing.

  27. Taj says:

    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = “301 Moved Permanently”;
    Response.AddHeader(“Location”,”http://www.google.com”);
    }

  28. I use JS and Meta tag to redirect my old blogspot blog to WP self hosted blog.. it works great for me.. But one thing is have to set 301 for each post so it get 301 to correct place..

  29. Great Tutorial very informative post. Thanks for sharing.



Subscribe without commenting




COPYRIGHT © 2011 SLASHSQUARE NETWORK. REPRODUCTION WITHOUT EXPLICIT PERMISSION IS PROHIBITED. ALL RIGHTS RESERVED.

Slashsquare
Mobile Version · About Us · Contact Us · Subscription · Advertise · Review · Write For Us · Archives · Privacy Policy · Disclaimer
Loading...