homepage Welcome to WebmasterWorld Guest from 54.166.110.222
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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




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

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?

 

Receptional Andy




msg:3613185
 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 /

galench




msg:3613215
 12:34 pm on Mar 28, 2008 (gmt 0)

Well that`s works fine!
But what the difference between ErrorDocument and RewriteRule?

Receptional Andy




msg:3613226
 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.

galench




msg:3613306
 1:57 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.

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 /

Receptional Andy




msg:3613326
 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.

galench




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

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved