EverWeb Codebox

Errors & htaccess

Custom Error Page

The 404 or Not Found error message is a response code indicating that the visitor was able to communicate with the server but the server could not find the page or file that was requested.

One sure fire way to drive visitors away from a website when they click an incorrect or defunct link is to present them with the generic 404 page. Not only does it not tell them what went wrong but it gives no clue as to what to do next.

An informative error page will help to keep those visitors who are led astray from leaving the website in disgust. It's also a good opportunity to direct them to a page that will help them find what they really want.

Creating the error page is simple since it is just another page of the website but is excluded from the navigation menu using the Page inspector. If some inspiration is required THIS PAGE may provide some ideas. Funnily enough, this page is usually named "error" so that its URL is - http://domain-name.com/error.html

The htaccess File

.htaccess is a configuration file that is placed in a directory on a server. It is a hidden file and would not normally be seen in an FTP application.

An htaccess file is a simple document that can be created in TextEdit.app. Make sure it is set to output plain text in the New Document tab of preferences under "Format".

The document described here is dual purpose in that it not only redirects 404s to the error.html page but also sends 403s there as well. This handy feature stops people accessing directories of assets and ripping them off.

Open a new doc in TextEdit and paste in this...


<Files .htaccess>

order allow,deny

deny from all

</Files>

Options -Indexes

ErrorDocument 403 /error.html

ErrorDocument 404 /error.html


It can be saved with no file extension or as .txt for the time being. If only the 404 is required, delete everything but this...


ErrorDocument 404 /error.html


Yes, it's that simple.

Vanishing Act!

Now for the tricky part.

Upload the file to the root folder on the server using an FTP application. The root folder is the one that contains the index.html for the website.

Once the file has been uploaded, double click it, remove the .txt extension if applicable and add a dot to the front of the name so that it becomes .htaccess

Now the file should disappear never to be seen again. To get to the file, use the server file manager to turn on "Show Hidden Files".

It's a good idea to keep a copy of the htaccess(.text) file locally so that changes can be made in the future. The modified file can then be uploaded, its file extension removed and the dot added to overwrite the original. This saves searching for the original hidden file.

Example Error Page

Hopefully, nobody will ever have to see This Page. It will appear when a bad or wrong link is clicked or the visitor tries to access a directory of assets.