I'm currently coding a site and I want to know the best alternative.
Should I add header("HTTP/1.0 404 Not Found") without redirecting or should I redirect and add a 404 header?
Redirecting means "What you asked for is actually over here".
If it isn't found, then it isn't found. Don't redirect.
Output a 404 status code, and then an HTML document that explains that whatever was requested wasn't found. You can then suggest an onwards journey by, for example, providing links to the main sections of the site or performing a search based on keywords extracted from the URL.
(The practical consequences of redirecting are that the URL vanishes from the address bar which makes it hard to look at an think "Oh, I mistyped that one letter, I'll just change it" or to copy/paste it into a bug report, etc).
header("Status: 404 Not Found"); //FastCGI
include("404.php");
exit;
URI remains the user asked.
You should redirect to an error page, but be sure you set status to 404. The error page can give the user tools to continue, like a sitemap, search, an explanation of what they were trying to load, and a little verbiage, like "We're sorry, but the page you requested at was not found."
Better yet, make your 404 page a script and use it to log the error so that you can become aware of common ones and fix them. It can be a tool for you too.
来源:https://stackoverflow.com/questions/9709192/redirect-404-or-just-404-header