So currently when a user loads a page that doesn't exist, or something goes wrong - I redirect users to a 404 page using header in PHP:
header('Location: www.website.com/404'); //This is simplified intentionally
This page displays a 404 icon with a link back to the homepage, and some other information
Recently in Google Webmaster tools I've been getting a few messages that I'm not returning a 404 page correctly.
Should I be returning http_response_code when displaying the 404 page? Or should I be handling 404 differently?
You can't use this. There can be only one status code. And in case of redirect it will be 301, not 404.
So you should make it
http_response_code(404);
include '404.html'; // or whatever
exit;
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