Forum Moderators: phranque

Message Too Old, No Replies

404 error with no redirect

         

surfpro203

5:19 pm on Jan 9, 2007 (gmt 0)

10+ Year Member



Currently, if somone goes to a page on my domain that does not exist, such as: www.mydomain.com/nsjljwoie.htm They are redirected to and www.mydomain.com/findnotfound.htm which displays the 404 error message.

QUESTION:
Is there any way to configure apache so that it does not redirect them to the filenotfound.htm but instead display a CUSTOMIZED 404 error massage while still displaying the "url incorrect url entered by the visitor - that does not exist" in the web brower.

If you go to a page that does not exist on this webmasterworld domain, you'll see that incorrect url stay in the browser url field, but you still get the 404 error message.

Finally, is doing this really necesary? I want to avoid google from indexing pages that no longer exist. Would simply, redirecting visitors to the filenotfound.htm page work for google. Or does google require no redirecting... the need the 404 error show for each incorrect page visited?

Any help would be appreciated.
Thanks
Surfpro203

jdMorgan

5:57 pm on Jan 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A properly-implemented custom 404 error page *does not* involve a redirect.

You might want to check your server response headers using the "Live HTTP Headers" extension to Firefox, or *several* on-line tools (because some of them only show the final server response, and will thus "hide" any intervening redirects), and verify that your implementation is correct. Based on what you've written, it sounds like it is not.

The single most common error in defining custom error documents on Apache is the use of a full URL in the directive, such as this incorrect example:


ErrorDocument 404 http://www.example.com/404error.html

As clearly stated in the ErrorDocument directive documentation [httpd.apache.org], this results in a redirect --specifically a 302-Found (Temporarily Moved) redirect-- to the 404 page, because the server assumes that the page is external to the current host domain. This is not the desired response, especially if search engine behaviour is taken into account.

The correct form is:


ErrorDocument /404error.html

using a local URL-path only, which will give a 404-Not Found status response, leave the client address bar unchanged, and display the contents of the error document.

Jim

surfpro203

6:54 pm on Jan 9, 2007 (gmt 0)

10+ Year Member



jdMorgan,

you nailed it on the head... I had the full url path and that was causing the redirect.

it's now
ErrorDocument /filenotfound.html

and working beautifully.

Thanks a million and have a Happy New Year.
Surfpro203

dgordon2

1:55 am on Jan 15, 2007 (gmt 0)

10+ Year Member



Instead of using a custom 404 error page, would it be better to use the following in your htaccess:

ErrorDocument /index.html

This way visitors clicking any bad links would never be sent to an error page and instead be sent to your sites home page.

Would there be any problems using that method? Especially in regards to Google. Is there any other aspect I may be overlooking where this wouldn’t be a good idea?

Thanks!

jdMorgan

3:14 am on Jan 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is an excellent way to invoke a duplicate-content "penalty" on your site.

I recommend that you use the HTTP protocol as it was designed -- A missing page should result in a 404-Not Found error, and an intentionally-removed page should result in a 410-Gone error.

When making technical decisions, the effects on your site's search engine ranking cannot be safely ignored.

Jim

dgordon2

4:51 am on Jan 16, 2007 (gmt 0)

10+ Year Member




Thank you for the advice! As you can see, I know just enough to be horribly dangerous. I am so glad I didn’t try to get cute with my 404 error page.

Thanks!

William

jdMorgan

5:05 am on Jan 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's best to acknowledge that a problem occurred, in simple terms, and then provide one or more solutions, such as a link to your home page or to your site map, or both.

Also stated elsewhere, but worth repeating, is that your custom error pages should have as few dependencies as possible. And the more severe the error, the fewer dependencies the error page should have.

For example, using a dynamically-generated 500-Server Error page is problematic, because if your script interpreter fails and causes a server error, then another server error will be invoked when the error handler tries to use the same script interpreter to create the error page, and another because of that -- ad infinitum.

I recommend a simple 500-Server Error page -- no images, no external stylesheets, no JavaScript, no server-side includes. Similar care should be taken with the 403-Forbidden and 503-Service Not Available error pages. 404 and 410 errors are not quite so critical, but a conservative fewest-possible-dependencies approach is safest.

Jim