joined:May 11, 2003
I have a custom 404.php
It works nicely, if the file or directory does not exist; e.g. it sends a proper 404 in the header.
My query is: How can I achieve the same clean result when partially running the index.php?
My page calls are like this: www.sub.domain.net/ for the index.php or www.sub.domain.net/?topic=3 for the same index.php but now with the querystring containing the page id to be served.
The pages does a database query and figures there is not page with the id=3. It is this case that I want to hand over to the 404.php page to send the 404 and display any options for the user.
When do the redirects in the index.php file (see below), I always get a 302 on the /?topic=3 and then a 200 on the 404.php.
It almost looks to me me that the behaviour might be correct, but it is not what I want. What I would like is the 404.php to show with a 404 status response header.
Any ideas how I can fix this? If at all :o)
I am using this code:
header('HTTP/1.0 404 Not Found');
header('Status: 404 Not Found');
I figured I must include line 1 to get a 404 in the server response; line 2 makes no difference.
When I add line 3 I get 302 > 200
I am also using ob_start(); at the beginning of index.php, which allows header changes until final output.