PHP header 404 not working

后端 未结 4 1278
孤独总比滥情好
孤独总比滥情好 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条回答
  •  萌比男神i
    2021-01-13 02:10

    Make sure your customized error page /404.html has the content size greater than 512 bytes. Many browsers like IE, Chrome etc don't show your customized page if content length of your custom 404 page is less than 512.

    UPDATE

    Based on your comments here is what I think is happening.

    If you look at the access.log or http headers in Firebug/HTTP Watch etc of this blank page, you'd see a 404 return code. Once the web server starts processing the PHP page, it's already passed the point where it would handle 404 handling by itself since your php file is actually FOUND. Now since your php code is merely returning status 404 without any content therefore a blank page gets displayed.

    Now since this is correct apache behavior and its up to you to create the contents for the 404 page. Something like this in your above php code will be fine I think:

    Not Found
    The requested URL " . $_SERVER["REQUEST_URI"] . " was not found on this server.
    
    "); ?>

提交回复
热议问题