Forum Moderators: phranque

Message Too Old, No Replies

403/404 Principles

         

bubster119

2:43 pm on Apr 11, 2007 (gmt 0)

10+ Year Member



I've created an .htaccess file to redirect 403 and 404 errors to my homepage:

ErrorDocument 403 http://www.example.com
ErrorDocument 404 http://www.example.com

I just wondered if anybody had any opinions as to whether the .htaccess approach is the most efficient/stable) way to acheive this and also whether as a principle if the redirection of 403/4s to the homepage is appropriate.

I would appreciate any feedback.

I just to confirm that I'm not going against any apache/web development conventions that I don't know about.

Cheers

[edited by: jatar_k at 3:08 pm (utc) on April 11, 2007]
[edit reason] please use example.com [/edit]

jdMorgan

3:28 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ErrorDocument 403 http://www.example.com
ErrorDocument 404 http://www.example.com

.htaccess is one way to achieve this -- I don't know about whether it's the "most efficient/stable way," but it's certainly one of the better ways to do it, as compared to slower/less efficient scripting or some other alternative.

However, the code you've posted is incorrect, and will actually result in a 302 redirect, instead of returning the proper server 403/404 response codes. The correct way to write it is:


ErrorDocument 403 /
ErrorDocument 404 /

This is well-described in the Apache core ErrorDocument documentation [httpd.apache.org], and I recommend a thorough read, especially of the notes at the end.

The use of the homepage as an error page is bad for several reasons. First, it may confuse the visitor. Second, it can lead to large duplicate-content issues, and negatively affect your ranking in search.

Each error should be handled by a page which describes the error in language suitable to your audience, and offers solutions such as links to your home page, category pages, and/or site map. You may also wish to ask visitors to report the problem if appropriate to your site's demographics, and if it offers any advantage to you.

Server response codes lie at the heart of proper Web operation, and I recommend that you pay very close attention to getting the details right at this level. Many 'mystery' site performance problems can be traced to bad implementations at this very basic level.

Server responses can be checked using the "Live HTTP Headers" extension to Firefox to make sure the response codes and all other details are correct.

Jim

bubster119

11:50 am on Apr 12, 2007 (gmt 0)

10+ Year Member



Thanks Jim, as always very helpful :)

g1smd

12:12 am on Apr 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I cannot recommend that you actually display your index page as an error document. It sounds like a recipe for disaster when dealing with search engines that probe sites to see what their error pages look like, and engines that take duplicate content issues into account.

Serve a custom page that tells the user that an error has occurred and then include a selection of site navigation to get the user clicking on their way towards the sort of content that they might have been looking for.

This page might be similar to your index page, perhaps a cut down version of it; but I would not be serving an exact rendition of the index page itself.

bubster119

1:12 pm on Apr 13, 2007 (gmt 0)

10+ Year Member



Thanks guys for the advice. I've scrapped the idea and i'm going to go with some fancy custom error pages instead ;)

jd01

4:47 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In using either a 'cut off' from the index page, or a neat, clean 'custom error' page I would recommend making sure you include "noindex,follow,noarchive" OR "noindex,nofollow,noarchive" to ensure SEs know you intend the page for visitors only, and do not want what could be a 'dupicate' page in their index.

Justin

g1smd

6:27 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good idea. Make sure that the custom 404 page cannot be indexed in any way, especially under its real URL.

bubster119

7:56 pm on Apr 15, 2007 (gmt 0)

10+ Year Member



g1smd could explain what you mean by "real url"?

g1smd

11:03 pm on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That would be www.domain.com/errors/error404.html.

If you ask for that URL you will get that page with a "200 OK" response, because the page really is at that location.