Website Construction - Error Processing
Websites get errors. The most common error is the 404 not found error when
someone enters the wrong webpage name.
The following is one approach to dealing
with those errors.
- Requirements:
- Benefits
- One error processing program.
Add Error Processing to your htaccess file.
- If you do not have an htaccess file, then you must create one.
- Search the Internet on htaccess for help.
- The instructions assume everything is in the root directory, but that is not required.
- Add one line to the htaccess file for each error you want to trap as follows.
ErrorDocument 400 /error-page.php?400
ErrorDocument 401 /error-page.php?401
ErrorDocument 403 /error-page.php?403
ErrorDocument 404 /error-page.php?404
ErrorDocument 500 /error-page.php?500
Create the error-page.php program.
- Following is the outline for the error-page.php program.
- The PHP portion will display the error and the error message.
- Add HTML to make the page more exciting and interesting.
<html>
<head>
<title>error-page</title>
</head>
<body>
<h1>Error</h1>
<?php>
$error = getenv(QUERY_STRING);
switch ($error) {
case "400" : $error_msg = "Bad Request"; break;
case "401" : $error_msg = "Authorization Required"; break;
case "403" : $error_msg = "Forbidden"; break;
case "404" : $error_msg = "Not Found"; break;
case "500" : $error_msg = "Internal Server Error"; break;
default : $error_msg = "Unknown Error"; break;
}
echo 'Error: ' . $error . ' ' . $error_msg;
?>
<p><a href="http://www.your-domain-name.com/index.htm">
Go to Home Page</a></p>
</body>
</html>
Results
The results will look like the following. The assumption is that everyone will add
HTML code to make it look more exciting or interesting.
Example
Follow the link to see one example:
http://www.wizard-creek.com/this-is-not-a-good-file-name