SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best Redirect with PHP

    I am updating my linking system for articles tonight and here is an example of the changes that will occur (only on new articles)

    mysite.com/news/4567

    to

    mysite.com/nw/4567-funny-video

    or something like that.

    If a new article is acccessed through the old link, I want to do a redirect to the new article. I was going to do this with php with the header function

    header("Location:$newpage");

    is this the best way to do it or do I have to send something else to avoid duplicates with search engines? Can doing this redirect transfer the PR as well?

    What is the best option here?

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Use a 301 redirect.

  3. #3
    I am Learning... Vick!'s Avatar
    Join Date
    Oct 2005
    Posts
    632
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you use .htaccess redirect? Its better than keep to duplicate pages and redirect one to another.

    Here is the code for 301 redirection using .htaccess -- Best method IMO

    Code:
    Redirect 301 /old/old.html http://www.you.com/new.html
    If you still want to use PHP redirect, here is the 301 redirect method recommended by stymiee

    Code:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.new-url.com" );
    ?>

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ended up doing a php, since the new urls are dynamic and based on new variables in our database.


    PHP Code:
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: $movlink");
    exit(); 
    I do the same with 404's right?

    PHP Code:
    header("HTTP/1.0 404 Not Found");
    header("Location:http://www.mysite.com/noexist.php");
    exit(); 
    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.


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
  •