In my .htaccess
I have
ErrorDocument 404 http://foo.com/404.html
It works, in the sense that I recover from any file not found error and show the 404 page instead, but the way it works is to redirect the erroneous URI using a 301 to my 404.html
page.
This is bad because search engines and crawlers will not end up seeing a 404 code, rather a 301 code and will not purge deleted pages from their indices.
Can I make Apache serve up the contents of this 404 page upon file not found errors, yet still return a 404 code instead of the 301?
Don't point at an external url
Apache's docs say:
Pointing at an external url will cause an actual redirect, whereas using a local url is internal.
So, to render the contents of a file simply point at it e.g.:
Use the right status code for the job
If the page used to exist and now does not, the correct response code is 410 Gone. 410 is the code to say "hey, that doesn't exist" whereas a 404 will only be taken to mean that after repeated attempts to access the now-none-existent page.
You should try to use absolute or relative path and not an URL
My apache2.conf :
Comment to Maxence’s and AD7six’s answers (I don’t have eneough reputation on serverfaul, and stack exchange reputations doesn’t count apparently):
I just solved the problem this way, but then the included pictures and styles were missing since the URL is still the URL that the userr was trying to call.
The solution is to add a base tag in the head of the 404 dowument like
or to use absolute URLs with or without protocol/domain name.