Handling Error Messages

By Laurie

Error Messages

Some of the errors you may have seen include 400 which is caused by bad syntax, 403 which is caused by a forbidden request for a page, or directory access. Lastly, the most common, 404 Not Found. That is, page not found

404 Error

In this Post we are going to look at the 404 error ‘Page Not Found’. Although we will concentrate on the 404 error the same solution can be used to intercept the other numbered error messages.

I am sure we’ve all been browsing from time to time and all of a sudden we get a glimpse of a flash of “404 Error Page not found” before we are taken to our ISP’s preferred error message page which tends to be full of adverts for which they are probably charging. (Nice work if you can get it!)

Think about this missed opportunity to interact with customers and potential customers. Not only can you interact with them but you can also find out about the usability of your site by entering into a dialogue with them and build that all important relationship from something that should not have happened.

It’s My 404 Error

Lets not forget that the error was caused by your website or your visitor. Lets look first at how we can redirect the error message to our own page so we can get our customer back on track. Or continue the dialogue.

What we are going to do is tell our website how we want it to behave when it encounters a numbered error. Instead of going to the default page, or even the ISP’s sales page we want it to come to our page. Or more accurately our error document, as it is called.

Our 404.html Error Page

So, lets return to the 404 error. We are going to produce a file called “error404.html” or “404.html” This is a standard html document where we will enter the following code:

html Start

Welcome to our 404 error page. The fact that you are here means that your attempted page request has failed.

This error means that there was no web page with the name you specified at the web site. This could happen for a variety of reasons:

  1. The document does not exist anymore.
  2. The document may have been renamed.
  3. The document has moved.
  4. The document may have been unavailable at the point of requesting it.
  5. The document url has become corrupt or malformed.

Use the browser back button (Usually at the top left of the page) to return to the previous page and try again. If when you try again, you are returned to this page, then please use the contact form below and let us know what you were trying to do so we can fix it.

html end

The above html code is the message and assistance that we want to provide. Remember to make this relevant to your target audience and if you dont know who they are then keep it very simple.

Upload The 404.html Document

Upload you personalised error document to the relevant domain such as http://www.your_domain.com/404.html This document does not have to be loaded onto the domain from where the error might occur. So, its quite easy to have one really usefull error document for all of your sites.

.htaccess File

Next, create a .htaccess file using NotePad or a similar editor that doesnt put hidden code into the file. So, dont use Word. Add lines which specify the substitution. Here are examples of specifying error documents
which will be called for a given error condition using relative and absolute addressing. (If you are going to use another domain for the 404.html file then you cannot use relative addressing.

ErrorDocument 404 /404.html
ErrorDocument 404 http://www.your_domain.com/404.html

Upload .htaccess File

Upload the .htaccess file into your home directory. You will not see it once uploaded since it gets hidden by the server.

Test It

Go to http://www.your_domain.com/anything_you_want.html

Assuming you replace your_domain.com with the actual domain you’re using and that you dont have a a file called anything_you_want.html, the error page you produced will appear.

PHP Problem

The code above will not work with php files. So, if you use PHP pages then you need to do the following:

Adding the following piece of code to the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.html

Create a file named “errordocument.html” containing your error message content. Or rename errordocument.html to 404.html

Home directory here means the directory your domain is pointing to in the Control Panel. It could be root directory (/.) or a directory named mydomain etc.

categoriaTechnical commentoNo Comments dataJanuary 7th, 2014


This author published 39 posts in this site.
Welcome to my blog. My interest are Judo, Self Employment, Internet and Off-Line Business.


FacebookTwitterEmailWindows LiveTechnoratiDeliciousDiggStumbleponMyspaceLikedin

You must be logged in to send a comment.