core
core copied to clipboard
Custom 404 page return 200
Hi, I was trying to use a custom html file to replace the default error page, but the body returns 200 OK instead of 404 Not Found. Tried the code for issue #343 and everything was fine, return 404
Flight::route('/status', function() {
Flight::response()->status(404);
echo 'The status is 404.';
});
then I try to Override using the example from the docs is when return 200 OK
Flight::map('notFound', function(){
// Display custom 404 page
include 'errors/404.html';
});
What should I do?
neither http_response_code(404);
, header("HTTP/1.1 404 Not Found");
or Apache ErrorDocument 404 errors/404.html
return 404 Not Found
My only solution is replace the original flight\Engine.php error message
Hi, this works for me:
Flight::map('notFound', function(){
Flight::response(false)
->status(404)
->write(
file_get_contents(__DIR__ . '/lib/views/404.htm')
)
->send();
});
You may also use:
Flight::stop(404);
Or you can use
Flight::halt(404, 'Not found');
@n0nag0n also can be closed.
Thanks @krmu