Search Engine Friendly Redirect

Discussion in 'PHP' started by Rezo, Mar 22, 2006.

  1. #1
    A 301 redirect is executed server-side which means that the visitor is never aware that they have been redirected, there is no time delay like with javascript


    To use the following PHP code you must change the file extension of the file you will be using to index.php instead of index.html.
    Now put the following code into your new index.php page, put ONLY this code, no need for <head>, <body> or any other tags. Change the page domain to the url you will redirect to.

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

     
    Rezo, Mar 22, 2006 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Even cleaner would be to just do this:

    <?php
    header("Location: http://www.newdomain.com/page.html", 1, 301);
    exit;
    ?>
    PHP:
     
    digitalpoint, Mar 22, 2006 IP
  3. tradealoan

    tradealoan Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes that is a good idea that keep your PR as well and yet allow you to redirect your vistiors to a new page :)
     
    tradealoan, Mar 22, 2006 IP