views:

84

answers:

3

I am developing a web site in PHP and I am using mod-rewrite to implement a single point of entry in index.php. From there I am using a dispatch table to dynamically create content for each URL (can be from a DB or other means).

I am not sure what is the correct way to treat URLs that are not in the dispatch table. I would like to return an error page with links to the site root and some possible guesses and a proper 404 code.

I am sure many of you have done such a thing and it is obvious how to do it but searching on google brings in front only results that are not relevant.

Thank you in advance for any solution or link a solution.

Solution up to now:

I am using this

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");

just before adding the content of the error page.

A: 

If you want to send a 404 code to the browser using PHP, you have to write to the header:

header("HTTP/1.0 404 Not Found");

apparently.

As for generating guesses, I'm guessing you'd do a LIKE query on the URL column.

Dan
Thanks. I used in the end header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");To preserve the actual protocol.
Daniel
A: 

I think what you are doing will probably work fine, in general.

As for what to put on the page, there's a few resources across the web. The one that comes to mind immediately is one that Opera put up recently. It uses Python as the example language, but it's pretty basic stuff.

Michael Johnson
+1  A: 

As long as what you're doing corresponds to HTTP Spec's definition of a well-formed status line and you're using 404 correctly. This is perfectly acceptable. You're doing it right!

Ollie Saunders