Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP header 404 not working

Why is this not working, as in the pre-set 404 page is not loaded:

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

.htaccess has the ErrorDocument 404 /404.html directive set.

Thank you.

like image 536
Francisc Avatar asked May 06 '11 16:05

Francisc


1 Answers

I unfortunately came across the same issue recently whilst working on a PHP project for work.

Sending a header is essentially only a 'status message', and doesn't make the browser or server show a particular page (although I believe some older versions of IE may show its default 404 page). This means that you will need to create your own 404 error message in your script, as the .htaccess error handling wont work.

My suggestion is to use something along the lines of

header("HTTP/1.0 404 Not Found");
include('./404.html');
exit;

I know it may seem stupid, but so far it's the only way I've found that will work.

like image 198
nahanil Avatar answered Oct 15 '22 00:10

nahanil