Redirecting to frontpage after 404 error in PHP

Posted by Saif Bechan on Stack Overflow See other posts from Stack Overflow or by Saif Bechan
Published on 2010-05-13T15:30:23Z Indexed on 2010/05/13 15:34 UTC
Read the original article Hit count: 268

I have a php web page that now uses custom error pages when a page is not found. The custom error pages are included in PHP.

So when somebody types in an URL that does not exists I just include an error page, and the error page starts with:

<?php header("HTTP/1.1 404 Not> Found"); ?>

This also tells crawlers that the page does not exist.

Now I have set up a new system. When a user types a wrong url, the user is sent back to the frontpage and a message is displayed on the frontpage. I redirect to the frontpage like this:

header('Location:' . __TINY_URL . '/');

Now the problem is PHP just sends back a 200 code, page found.

How can I mix these two to create a 404 code on the frontpage.

And is this overall a nice way of presenting and error page.

© Stack Overflow or respective owner

Related posts about php

Related posts about error-handling