How to do 301 redirect through PHP ?

Discussion in 'PHP' started by poseidon, Jan 31, 2008.

  1. #1
    Well instead of htaccess, I am looking to redirect some of my webpages using php.

    So I want to redirect www.example.com/old.php to www.example.com/new.php by putting the php code in old.php. :)

    All help/code will be appreciated.

    Is this the best Code to use for php redirection ?

    
    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.new-url.com" );
    ?> 
    
    Code (markup):
     
    poseidon, Jan 31, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Yes. Just keep in mind that the "h" in "header" should not be capitalized.

    And you could also do it this way:
    
    header('Location: http://new-url.com', true, 301);
    
    PHP:
     
    nico_swd, Feb 1, 2008 IP