Some redirect types

Discussion in 'Search Engine Optimization' started by GMBRDILOS, Apr 17, 2009.

  1. #1
    PHP Single Page Redirect

    In order to redirect a static page to a new address simply enter the code below inside the index.php file.

    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.com/page.html");
    exit();
    ?>

    PHP Canonical Redirect

    The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain. The code below redirects the visitors of the http://domainname version to http://www.domainname.

    <?php
    if (substr($_SERVER['HTTP_HOST'],0,3) != ‘www’) {
    header(’HTTP/1.1 301 Moved Permanently’);
    header(’Location: http://www.’.$_SERVER['HTTP_HOST']
    .$_SERVER['REQUEST_URI']);
    }
    ?>

    Apache .htaccess Canonical Redirect

    Follow the same steps as before but insert the code below instead (it will redirect all the visitors accessing http://domainname to http://www.domainname.)

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

    ASP Single Page Redirect

    This redirect method is used with the Active Server Pages platform.

    <%
    Response.Status="301 Moved Permanently"
    Response.AddHeader='Location','http://www.new-url.com/'
    %>

    ASP Canonical Redirect

    The Canonical Redirect with ASP must be located in a script that is executed in every page on the server before the page content starts.

    <%
    If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://www."
    & Request.ServerVariables("HTTP_HOST")
    & Request.ServerVariables("SCRIPT_NAME")
    End if
    %>

    HTTP 301 Redirect in ASP-VBScript

    <%@ Language=VBScript %>
    <%
    ' Permanent redirection
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "http://www.somacon.com/"
    Response.End
    %>

    Redirection with Javascript

    <html>
    <head>
    <script type="text/javascript">
    window.location.href='http://www.somacon.com/';
    </script>
    </head>
    <body>
    This page has moved to <a href="http://somacon.com/">http://somacon.com/</a>

    </body>
    </html>

    Redirection with META Refresh

    <html>
    <head>
    <meta http-equiv="refresh" content="0;url=http://www.somacon.com/">
    </head>
    <body>
    This page has moved to <a href="http://somacon.com/">http://somacon.com/</a>
    </body>
    </html>
     
    GMBRDILOS, Apr 17, 2009 IP
  2. justAdream

    justAdream Active Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    Hello

    How i can customize this code my site?

    ASP Canonical Redirect

    The Canonical Redirect with ASP must be located in a script that is executed in every page on the server before the page content starts.

    <%
    If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://www."
    & Request.ServerVariables("HTTP_HOST")
    & Request.ServerVariables("SCRIPT_NAME")
    End if
    %>

    please help me

    http://forums.digitalpoint.com/showthread.php?t=1538261

    thank you
     
    justAdream, Oct 19, 2009 IP