Updated. Originally published Jan 2, 2004
Error messages are the messages that are displayed when a visitor to your site encounters a server error. The most common error messages are 404: File Not Found and 403: Access Forbidden. The 404 error message is displayed when a visitor to your site tries to access a page that does not exist on your server. The 403 message is displayed when a visitor tries to enter an area on your site that is off limits to the public.
You can customize your error messages so that instead of seeing an ugly server message, your visitor sees instead a personalized note from you. The methods are different depending on if you are doing static (the default) or dynamic publishing in Movable Type.
Static Publishing Error Templates
If you use an Apache server you can customize your error messages by creating or editing your .htaccess file. Here are the steps:
Step 1: Create 403 and 404 error html documents:
Create new html files with the error messages that you want to convey for 403 errors and 404 errors. Save the files as 403.html and 404.html.
You can word the contents of these documents however you please. Place the html documents in your public_html directory.
Step 2: Change or create your .htaccess file.
Inside your public_html directory, or one of its subdirectories, you may have a file named .htaccess (see What is .htaccess?). If an .htaccess file isn't already there, create a simple text file named .htaccess in a text editor. Now add the following lines to your .htaccess file.
ErrorDocument 403 PATH ErrorDocument 404 PATH
Make sure to replace where it says PATH with the path to that error message.
For example, your .htaccess file may look something like this if you have uploaded the html files and the .htaccess file to the same directory:
ErrorDocument 403 /403.html ErrorDocument 404 /404.html
Step 3: Upload your new .htaccess file to your server using an ftp program.
Then test it out! This method can also be used with the other error codes: 400, 401, and 500.
Dynamic Publishing Error Templates
If you use dynamic publishing, Movable Type will point to the Dynamic Pages Error Template in your blog if a page can't be found. The default template body of this template is:
<p>The requested page could not be found.</p> <h4 class="error-message"><$MTErrorMessage$></h4>
At the time of this writing, the MT Manual specifies that the the
$MTErrorMessage$ tag can only be used in the Comment Error Template. The tag is replaced with the text of the error that occurred in the comment submission process. However, this tag also appears in the default Dynamic Pages Error Template. So, I'm assuming that if there is a system generated specific error message, the
$MTErrorMessage$ tag will produce it. (Sometimes the MT Manual is a bit out of date.) You can change the message that comes between the p tags and replace
The requested page could not be found. with something else.
In MT 3.12 the tag
<MTHTTPErrorCode> was introduced. The tag only works with dynamic pages and can be used with a little PHP to generate different error messages for different error codes. Arvind has documented how to use the MTHTTPErrorCode tag to customize error messages in his Movalog tutorial - Custom Error Messages.
I recently changed all of the file extensions on one of my blogs from html to php. Scripty Goddess wrote a 404 redirect PHP script that automatically redirects visitors to the .php file when they try to access the .html file that is no longer there. This script works if the URL paths are the same except for the html and php extensions.
- Apache.org tutorial on .htaccess
- Error code definitions
- Dynamic Pages Custom Error Messages
Cool custom error messages:
- Bah! I've messed up.
- Nothing here by that name
- Sorry, but that page you were looking for can't be found.
- It appears you've landed on a page that doesn't exist.
- Tried to dash in from the rain?
- Once upon a time there was a web page. It was witty and smart.
- Wrong Page. Your artfulness has failed you.
Have one to recommend? Let me know in the comments!