Tutorials, Articles, SEO, CMS, MySQL - Unofficial 110MB Support Center
Article Search:
Navigation
Home
Articles / How-To's
Downloads
110MB Upgrades
Support Forum
Useful links
Search
Site Map
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Things to Do
Forum Threads
Newest Threads
SEO, Using anchor te...
Official PHP Fusion ...
Box 12
any postions open :P ?
How To Save Time By ...
Hottest Threads
Official PHP Fusi... [7]
any postions open... [7]
Box 12 [4]
Do you have what ... [4]
Add these downloads [3]
Users Online
Guests Online: 4
No Members Online

Registered Members: 75
Newest Member: go2
Latest Articles
To protect your images...
How to add your site t...
Nwwl Redirect
Create custom error pa...
SMF 2.0 Beta 3 with SQ...
phpBB3 "Olympus" Relea...
PHP and MySQL security
How to install E107
Wordpress update the e...
Making your own RSS feed
Create custom error pages with .htaccess
Hi,

In this article I am going to show you how to use .htaccess to create a custom error page instead of having the 110mb default. As a bonus Im also going to show you how to use PHP to make a universal error page for all the errors that are possible.

Ok, so first we need to create and configure a .htaccess file. This is very simple, just open up your favorite text editor (Windows : Notepad) and paste the following

ErrorDocument 500 http://yoursite/error.php?e=500
ErrorDocument 404 http://yoursite/error.php?e=404
ErrorDocument 401 http://yoursite/error.php?e=401
ErrorDocument 403 http://yoursite/error.php?e=403

(Remember to change "yoursite" to the url of your website) Save this as .htaccess

If the file editor saves it as something like .htaccess.txt Make sure to rename it and remove the .txt


Once you have saved it you can upload it to your sites root folder.


--- The error page ---

Now im going to show you how to use switch(), $_GET[''] and echo() in PHP . What we are going to do is very simple, so dont be scarred by the fact we are using PHP.

We are going to create a page that can be used for multiple purposes, depending in what  = e in the URI.

Copy and paste this code into the text editor you used earlier
 <?php
$errorCode = $_GET['e'];

switch($errorCode){
default :
$errorDescription = "Unspecified Error";
break;
case "401" :
$errorDescription = "Access to this resource requires Authorization";
break;
case "403" :
$errorDescription = "Access to this resource is forbidden";
break;
case "404" :
$errorDescription = "The page you requested could not be found";
break;
case "500" :
$errorDescription = "The server encountered an unexpected condition which prevented it from fulfilling the request";
break;

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo"$errorCode"?> Error</title>
<style type="text/css">
<!--
body {
background:#CCCCCC;
}
#errorCode {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 22px;
    font-style: oblique;
    font-variant: normal;
    color: #000000;
}
#errorDescription {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-style: normal;
    color: #000000;
}
#errorBox{
margin-top:35%;
margin-bottom:25%;
height:50%;
width:30%;
margin-left:35%;
margin-right:35%;
background:#FFFFFF
}
-->
</style>
</head>

<body>
<div id="errorBox">
<div id="errorCode"><?php echo "$errorCode";?></div>
<div id="errorDescription"><?php echo "$errorDescription";?></div>
</div>
</body>
</html>

Save that as error.php and upload it to your root directory

That will check what e=  in the URI and then will change the description depending on the error code specified in the URI.


To test if this works, in your internet browser, type your website followed by something like :
gdfgusdhfgsd0hgiofdghiosdghnuiofdghnsdofgidfg.php

So it would be something like :

http://yoursite.110mb.com/gdfgusdhfgsd0hgiofdghiosdghnuiofdghnsdofgidfg.php

Assuming you dont have a page called that you should be redirected to error.php?e=404


Thanks for reading this article And I hope you found it helpful

Posted by brad82 on August 12 2008 17:35:40 0 Comments · 1107 Reads · Print
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Copyright © The Unofficial 110MB Support Center 2007
Theme based on Valencia, created by PHP Fusion Themes