Custom Error Pages
Published on the 30th of January 2005
Custom error pages are a nice feature to add to any site. To complete this tutorial you need PHP and access to the .htaccess file.
In the .htaccess file add this code:
.htaccess
ErrorDocument 400 /error.php?e=404
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500
Now create a page in the same folder as .htaccess and name it error.php. In the page add this code:
PHP
<?php
if (!isset($e)) {
$e = "404";
}
if ($e == "400") {
$text = "Sorry Bad request.";
}
elseif ($e == "401") {
$text = "You are unauthorized to view this page!";
}
elseif ($e == "403") {
$text = "This page is forbidden.";
}
elseif ($e == "404") {
$text = "This page cannot be displayed. The file may have been moved to a different location.";
}
elseif ($e == "500") {
$text = "Internal server error.";
}
else {
$text = "An error has occurred";
}
?>
<?php echo $text; ?>
Please visit our <a href="/index.php">Home Page</a>
Error: <?php echo $e; ?>
Ip: <?php echo $_SERVER['REMOTE_ADDR']; ?>
Now you have some simple custom error pages that are very easy to edit.

