404 Header PHP

Discussion in 'PHP' started by rederick, Nov 7, 2005.

  1. #1
    Hi,
    I have a website that is drivin by a database, the urls are
    /index.php?id=1 ... I rewrite them to filename.php, this is all great.

    Now the problem is when someone requests a page that does not exists, I have to check the database to see if the page record is in the database , if not I call ...

    
    header('HTTP/1.0 404 NOT FOUND');
    echo file_get_contents('404.php');
    exit();
    
    PHP:
    This will display the custom error message page and send the proper headers. Is this the safe thing to do from an seo perspective?

    edit:If I used header( 'Status: 404' );
    I get a 200 responce, but hte status is 404 ... this does not seem better?
     
    rederick, Nov 7, 2005 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
    Probably better to make it HTTP1.1... but either way it should work fine...
    header ('HTTP/1.1 404 Not Found');
    PHP:
     
    digitalpoint, Nov 7, 2005 IP
  3. expat

    expat Stranger from a far land

    Messages:
    873
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    as Shawn said works well

    Litle tip: use php error page to send yourself a mail thus you don't need to trawl through error logs. Something like this......

    if ($HTTP_REFERER <> "")
    {
    $today = date("j F Y, G:i:s");
    $message = "Date and Time: $today\nRequest URL: http://$SERVER_NAME$REQUEST_URI\nReferring page: $HTTP_REFERER\n\nClient: $HTTP_USER_AGENT\nRemote IP: $REMOTE_ADDR\n\n";
    $message .= "This is an automated message.\n\nHave a nice day.";
    mail(), "Error 404", $message, "From: : errormail<A href="mailto:errormail@mydomain.com");">@mydomain.com");

    }


    Expat
     
    expat, Nov 7, 2005 IP