Creating Custom Error
Pages - Part II
OutFront News Article: June, 2002
Now your messages and
error pages are created and contain useful content for
those that may end up on them. The next step is to
ensure that users are served these pages when an error
occurs.
Serving up the Pages
How you do this varies according to the server type. I have included instructions below for Unix/Linux servers running Apache. Windows servers have a different method and, if your host allows it, you may have a means of defining custom messages in your site control panel. If not contact your host to find out if they can do it for you.
If you are unsure what type of server your site is
on, enter your URL on this page to find
out.
Unix/Linux servers running Apache
Apache uses the .htaccess file to redirect users to custom error pages. So, you are going to need to either create or edit your site's .htaccess file.
Creating/Editing a .htaccess File
What is a .htaccess file? Well, that is an article all to itself but basically it is a file that controls access to the
other files within a directory. You can have just one in the main (root) directory, controlling access to your entire site, or you can have separate files in each directory.
To work with .htaccess files you will have to FTP your site. In the main directory you should see the file .htaccess at the top of the file list. If there is none visible you may have to tell your FTP client to 'show hidden files'. Look in your FP client help section to find out how to do this.
Once you find it download a copy to work on and save a back up copy as well in case you mess up!
You need to add the following to the end of your .htaccess file, after any content already there:
# Added for Custom Errors
ErrorDocument 400 /errors/error400.htm
ErrorDocument 401 /errors/error401.htm
ErrorDocument 403 /errors/error403.htm
ErrorDocument 404 /errors/error404.htm
ErrorDocument 500 /errors/error500.htm
It is important that you use the exact syntax above - for example 'ErrorDocument', not 'errordocument'. You can of course change the file paths to the correct ones for your site.
That's all there is to it. Save your file and upload it.
You can either add the part referencing custom error pages to the main .htaccess file in your root directory, in which case it will apply to the entire site, or you can add it to individual directories. In the latter case it is possible to have separate error pages for each directory, but this is probably overkill in most cases.
What if you have no .htaccess file?
Check first to make sure it is not there, it may just be hidden. You can chose to display hidden files and folders in your FTP client - see the help section of whatever you use for FTP to find out how.
If it really isn't there, no problem. Create a plain text file containing the content above, save it as htaccess.txt, upload to your root directory and once it is there rename it .htaccess. Don't be alarmed if it then seems to disappear - many servers are configured to hide .htaccess files.
<<
Part 1: Creating Custom Error Pages
Katherine
Nolan
OutFront Moderator
www.inkkdesign.com
|
 |
|