Need 301 redirect code

Discussion in 'Search Engine Optimization' started by leadshome, Apr 7, 2011.

  1. #1
    I need 301 redirect htaccess code. please anyone provide me.
     
    leadshome, Apr 7, 2011 IP
  2. techlunatic

    techlunatic Peon

    Messages:
    227
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    IIS Redirect

    In internet services manager, right click on the file or folder you wish to redirect
    Select the radio titled "a redirection to a URL".
    Enter the redirection page
    Check "The exact url entered above" and the "A permanent redirection for this resource"
    Click on 'Apply'
    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" );
    %>

    CGI PERL Redirect

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

    Ruby on Rails Redirect

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

    Redirect Old domain to New domain (htaccess redirect)

    Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
    The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

    Please REPLACE www.newdomain.com in the above code with your actual domain name.

    In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.

    Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.


    Redirect to www (htaccess redirect)

    Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
    The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

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

    Please REPLACE domain.com and www.newdomain.com with your actual domain name.

    Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

    PS : You would have got the same had you googled the same query instead of asking in the forum , its not like that requires critical acclaim or something ! What I did was the same thing - copy paste from a site which..............wait for it ............I Googled for !!
     
    Last edited: Apr 7, 2011
    techlunatic, Apr 7, 2011 IP
  3. bogs

    bogs Active Member

    Messages:
    2,142
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    80
    #3
    bogs, Apr 7, 2011 IP
  4. daisy scott

    daisy scott Active Member

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    thanks for yr valuable info..its great
     
    daisy scott, Apr 8, 2011 IP
  5. ianspencer

    ianspencer Member

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #5
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
     
    ianspencer, Apr 8, 2011 IP
  6. smartcomsci

    smartcomsci Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks sir., I try to do it and found it useful to help my web too.
    Good luck
     
    smartcomsci, Apr 8, 2011 IP
  7. RamCity

    RamCity Peon

    Messages:
    732
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes. He forgot some more.

    This is .htaccess redirect. And this is mostly used redirect method.
     
    RamCity, Apr 8, 2011 IP
  8. parveen1989.seo

    parveen1989.seo Guest

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    i need asp.net redirect code which can we use for redirection
     
    parveen1989.seo, Apr 8, 2011 IP
  9. RamCity

    RamCity Peon

    Messages:
    732
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you move your eyes to top?

    techlunatic
    has already given the ASP.NET redirect code.
     
    RamCity, Apr 8, 2011 IP
  10. outshinesol

    outshinesol Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Wow techlunatic techlunatic you have done really good job. What a great post thanks
     
    outshinesol, Apr 8, 2011 IP
  11. Adnan959

    Adnan959 Member

    Messages:
    894
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #11
    Great post!
     
    Adnan959, Apr 8, 2011 IP
  12. seoaccount

    seoaccount Peon

    Messages:
    499
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Search on Google. Code will be different based on different programming languages. So, use the code in the programming language in which your website has built
     
    seoaccount, Apr 8, 2011 IP
  13. jacuzzi

    jacuzzi Guest

    Messages:
    470
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    yea i may agree to Techlunatic's view, the following code may be simply get to get 301 redirect..its good fromseo point too.
     
    jacuzzi, Apr 8, 2011 IP