Forum Moderators: phranque
So, we can use in our htaccess file this code:
ErrorDocument 404 http://www.example.com
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^404.shtml$ http://www.example.com [R=301,L]
What`s more correctly?
Therefore I have noticed that "ErrorDocument 404" code masks url, for example, if we request http://www.example.com/pagenotexist.htm
We will see content from http://www.example.com (i.e. index.htm) but with url in address bar - http://www.example.com/pagenotexist.htm
This why i think second rule is more correct!
And you?
The problem is that your errordocument is a full URL which will always trigger a redirect in Apache. Use the below instead:
ErrorDocument 404 /
You could probably replicate this, including status code with a rewriterule, but I doubt you would ever need or want to since errordocuments are designed for this purpose.
Your rewrite rule is just displaying the content of the 404 page, but it's not returning the correct (404) status code. That means broken links are essentially valid pages and will, for instance, get indexed by search engines.
Understood!
And it`s mean what RewriteRule does not give me any error log information!
But if I will use ErrorDocument, all "not found pages" will be displayed in my Error log!
Right?
So, I also made:
ErrorDocument 400 /
ErrorDocument 401 /
ErrorDocument 403 /
ErrorDocument 404 /
ErrorDocument 500 /
I would consider making custom pages a bit more relevant to the error you are returning, though: otherwise you risk visitors ending up at the homepage and not understanding that an error has occurred.