Welcome to WebmasterWorld Guest from 50.16.78.128

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

404 Page - "ErrorDocument 404" or "RewriteRule"?

   
9:34 am on Mar 28, 2008 (gmt 0)

5+ Year Member



Make 404 page redirect to home page or custom - it`s another post...
I want discuss here how to redirect correctly 404 page!

So, we can use in our htaccess file this code:


ErrorDocument 404 http://www.example.com

or

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?

11:56 am on Mar 28, 2008 (gmt 0)



Hi Galench,

The problem is that your errordocument is a full URL which will always trigger a redirect in Apache. Use the below instead:

ErrorDocument 404 /
12:34 pm on Mar 28, 2008 (gmt 0)

5+ Year Member



Well that`s works fine!
But what the difference between ErrorDocument and RewriteRule?
12:40 pm on Mar 28, 2008 (gmt 0)



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.

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.

1:57 pm on Mar 28, 2008 (gmt 0)

5+ Year Member




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 /
2:10 pm on Mar 28, 2008 (gmt 0)



That's right.

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.

2:28 pm on Mar 28, 2008 (gmt 0)

5+ Year Member



Yes! I understand it!
I hope I haven`t many error pages! :)
But, anyway, it`s necessary to check frequently Error log.

Thanks for excellent replies!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month