Reputation: 544
What should happen when a page doesn't exist on your site? If I have a custom error page set up in my .htaccess, I get a 302 temporary redirect to my 404 page (where I send 404 headers). Is this how it should work? Or should I do a 301 permanent redirect to the error page? I'm using php and Apache.
Upvotes: 2
Views: 2677
Reputation: 116110
If you got a static error page, say 404.html, that apache shows when a page is not found, and you need to be able to serve 404 pages for your dynamic pages as well, you can do that by sending the 404 header from PHP and feed the error page as well:
<?php
header("HTTP/1.0 404 Not Found");
readfile("404.html");
?>
Upvotes: 1
Reputation: 943510
If it never existed, you should send 404 Not Found
.
If it used to exist, but doesn't any more, you should send 410 Gone
.
Set up your server to send the error response directly.
You shouldn't redirect to an error page. That essentially means the conversation would go:
Bait and switch is never nice.
Upvotes: 7
Reputation: 52372
The non-existent page has not "temporarily moved" (301) or "permanently moved" (302) to a page about the file not existing, it doesn't exist. The correct header to send is a 404, not anything else.
Don't redirect anywhere, instead serve your "file not found" page content at the URL that was requested.
Upvotes: 5