PHP header 404 not working

后端 未结 4 1273
孤独总比滥情好
孤独总比滥情好 2021-01-13 01:52

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

4条回答
  •  粉色の甜心
    2021-01-13 02:00

    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.

提交回复
热议问题