• Breaking News

    301 and 302 redirect

    When you remove a page or product from your website, it gives No-Page-Found error for that URL because that URL is gone. The server will fetch 404 error (No page found) to the visitors and it will increase the bounce rate as well as negative impact of the ranking of your website on Google and other search engines.

    Now, there are two redirects for a gone page. 
    301 redirects - This is permanent redirection of a gone page to a new URL which is in force.
    302 redirects - This is temporary redirection of a gone page to a new URL until the same (gone page) is redesigned or redeveloped. It is generally used in maintenance mode.

    1. 301 redirection using .htaccess apache server (use the following code)
    Redirect 301 /old-url.html http://www.mydomain.com/new-url.html

    2. 301 redirection using php (use the following code)
    <?php
    // PHP permanent URL redirect - generated by www.rapidtables.com
    header("Location: http://www.mydomain.com/new-url.html", true, 301);
    exit();
    ?>

    3. 301 redirection using html (use the following code)
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="refresh" content="0; url=http://www.mydomain.com/new-url.html">
    </head>
    <body>
    </body>

    4. 301 redirection using ASP.NET (use the following code)
    <script language="C#" runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
       Response.Status = "301 Moved Permanently";
       Response.AddHeader("Location","http://www.mydomain.com/new-url.html");
       Response.End();
    }
    </script>

    5. 301 redirection using ASP redirect (use the following code)
    <%@ Language="VBScript" %>
    <%
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "http://www.mydomain.com/new-url.html"
    Response.End
    %>

    --------------------------------------------------------------------------------------------

    HTTP status codes
    Status codeStatus code nameDescription
    200OKsuccessful HTTP request
    300Multiple Choices
    301Moved Permanentlypermanent URL redirection
    302Foundtemporary URL redirection
    303See Other
    304Not Modified
    305Use Proxy
    307Temporary Redirect
    404Not FoundURL not found
    --------------------------------------------------------------------------------------------

    302 redirection

    1. using .htaccess apache (use the following code)
    Redirect 302 / http://www.mydomain.com/new-url.html

    2. using php (use the following code)
    <?php
    header("Location: http://www.mydomain.com/new-url.html");
    exit();
    ?>

    3. using HTML meta tag (use the following code)
    <meta http-equiv="refresh" content="0;url=http://www.mydomain.com/new-url.html">

    4. using Java Script (use the following code)

    <script type="text/javascript">
    window.location.replace("http://www.mydomain.com/new-url.html");
    </script>
    =============================================================

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728