SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which of these PHP redirects should I use?

    Hi;

    I don't know PHP and so I'd like feedback on the best PHP code to use for a 301 redirect (that Google recognizes)


    <?php

    header('HTTP/1.1 301 Moved Permanently');

    header('Location: http://www.site.com/newpage');

    ?>




    <?php

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: [newdomain.com...]
    exit();

    ?>



    <?php

    header( 'Location: http://www.yoursite.com/new_page.html' ) ;

    ?>






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

    I found all of these online and am not sure if one is "better" than the others (in terms of retaining link equity)

    Thanks

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,138
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    The first two examples are the same, the second has a syntax error, but the concept is the same.

    Now what differs from the first 2 examples and the last? The last one doesn't tell search engines that the page is permanently moved and they need to update their index.

    So if you want to indicate a permanent move, use the first example (the second example is moot, since it is the same but with syntax errors).

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The 2nd one also has this:

    exit();

    ------

    Should I include that part?

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,138
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You can. It just ensures if you have any code following that line, it won't be executed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •