I am attempting to throw my own 404 in PHP depending on certain GET vars. But the following is not working. I can confirm that the pge header is coming back with a '404 status code' though. .htaccess just doesn't seem to be redirecting correctly. Am I missing something?
PHP Code:
if(!$_GET['page']){
header('HTTP/1.0 404 Not Found');
}
.htaccess Code:
ErrorDocument 404 /404.html
Many thanks!
As far as Apache's concerned, it's done its job as it has properly found the page/script that the user's request called for. The fact that the script is outputting a 404 header is irrelevant to Apache, since its job was completed properly.
You'd need to have your PHP script output the 404 header, and include the page the Apache 404 handler points at it:
if (!$_GET['page']) {
header('HTTP/1.0 404 Not Found');
include('404.html');
exit();
}
Don't do a redirect to the 404 page, as that'd just turn the hit into a normal GET request, with a 200 OK result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With