I use .htaccess RewriteRules to pass the url to index.php. If the specified page name isn’t found in the database, I want my script to throw proper 404 responses.
The way I have tried to achieve this is:
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
Analysing the HTTP responses in my browser, the response comes back fine:
HTTP/1.1 404 Not Found
However, I would like to be able to output a friendly 404 page, but anything after the header() function gets disregarded, and anything before … well … that’d be stupid.
Can anyone suggest how to output a 404 error message from the script?
Thanks.
You have to make sure the output (or ErrorDocument) is larger than 512 bytes as to make sure Internet Explorer doesn’t display it’s own error-page. This is probably why you have experienced any output after the header doesn’t get displayed.