CWC index .

Customizing Error Pages

5 March 2007; last modified 25 September 2007

        ___    /
      _/   |   \,^%---
     |_____|    <_ \ Fear not. It's quite simple....
       --- ==   >/
     [_____]  __>,^
ejm   |   |  //| |

When errors occur, you probably want the error pages that pop up to look like they actually belong to your site. (The default file extension for Crosswinds hosted sites' error pages is .shtml.)

404 not found | 500 internal server error | 401 authorization required | 403 access forbidden | 400 bad request | htaccess

customizing '404 not found' pages

Of all the error pages, the 404 not found may be the most useful. It is for those occasions that "not found" files occur. They may be from misdirected links to your site. Or perhaps you have moved some files. Or someone has mistyped a file name in linking to your site.

Whatever it is you are looking for at http://yourdomainname/notfoundfilename does not exist on this site. Please check for typo(s) and/or browse through the menu on yourdomainname's homepage.

To produce the above on a 404 not found page that uses the style of your site, use the following coding:

<html>
<head>
<title>your domain name - 404 not found</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="/yourstyle.css" type="text/css">
</head>
<body>

[your header]
<p>Whatever it is you are looking for at <strong>http://<!--#echo var="SERVER_NAME" --><!--#echo var="REQUEST_URI" --></strong> does not exist on this site. Please check for typo(s) and/or browse through the menu on <!--#echo var="SERVER_NAME" -->'s <a href="/">homepage</a>.</p>

[your footer]

</body></html>

Save it as 404.shtml and place the file in your root folder.

customizing '500 internal server error' pages

From time to time, internal server errors occur. This can affect phpBB forums, wordpress blogs, or any file with the extension .php. It's nice to let your visitors know that they have arrived at the correct location. You may want to say something along these lines:

An internal server error has occurred on yourdomainname. Please wait a short time and try again.

Company Name
address
city, country
ph: 1 555 555 5555 , e: youraddress@yourdomain.com

To produce the above on a 500 internal server error that uses the style of your site, use the following coding:

<html>
<head>
<title>your domain name - 500 internal server error</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="/yourstyle.css" type="text/css">
</head>
<body>

[your header]

<p>An internal server error has occurred on <a href="/"><!--#echo var="SERVER_NAME" --></a>. Please wait a short time and try again.</p>

<p>Your Company Name<br>
address<br>
city, country<br>
ph: 1 &#053;55 &#053;55 &#053;555 , e: youraddress&#064;yourdomain&#046;&#099;om</p>

[your footer]

</body></html>

Note that the phone number and email address use character entities. Save it as 500.shtml and place the file in your root folder.

customize database error message page on phpBB
customize error message page on Wordpress

customizing '401 authorization required' pages

You may have some sensitive areas that require passwords to gain access. Here is a possible wording for the message for unauthorized viewers:

Authorization is required to view this file on yourdomainname

To produce the above on a 401 authorization required that uses the style of your site, use the following coding:

<html>
<head>
<title>your domain name - 401 authorization requiredt</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="/yourstyle.css" type="text/css">
</head>
<body>

[your header]

<p>Authorization is required to view this file on <a href="/"><!--#echo var="SERVER_NAME" --></a></p>

[your footer]

</body></html>

Save it as 401.shtml and place the file in your root folder.

customizing '403 access forbidden' pages

Sometimes you just don't want anyone to ferret around through some folders. (You can deny access to files or folders by going to your cpanel.) And you may not even want some people to realize that they are attempting to see forbidden fruits...

Access for this file is unavailable at this time. Please browse through the yourdomainname site menu for an alternative.

To produce the above on a 403 access forbidden page that uses the style of your site, use the following coding:

<html>
<head>
<title>your domain name - 403 access unavailable</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="/yourstyle.css" type="text/css">
</head>
<body>

[your header]

<p>Access for this file is unavailable at this time. Please browse through the <a href="/"><!--#echo var="SERVER_NAME" --></a>  site menu for an alternative.</p>

[your footer]

</body></html>

Save it as 403.shtml and place the file in your root folder.

customizing '400 bad request' pages

A few computers just aren't equipped...

Your browser sent a request that the server for yourdomainname could not understand.

To produce the above on a 400 bad request that uses the style of your site, use the following coding:

<html>
<head>
<title>your domain name - 400 bad request</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="/yourstyle.css" type="text/css">
</head>
<body>

[your header]

<p>Your browser sent a request that the server for <a href="/"><!--#echo var="SERVER_NAME" --></a> could not understand.</p>

[your footer]

</body></html>

Save it as 401.shtml and place the file in your root folder.

htaccess

With crosswinds.net, as long as you upload your error files with .shtml file extensions to your root folder, you do not have to do anything else. However, you may wish to use different file names or extensions. To instruct your site where to find your custom error pages, open up (in a text editor) the file called .htaccess, located in your public_html\ directory. Add the following lines (note the leading slash preceding the file name) and re-upload via ASCII:

ErrorDocument 404 /notfoundhere.html
ErrorDocument 400 /noideawhatyoumean.php
ErrorDocument 401 /authorizationplease.shtml
ErrorDocument 403 /takeahike.shtml
ErrorDocument 500 /internalserver.shtml

If you do not see a file called .htaccess in your root directory, check that you can see all files. In FTP, type -al (hyphen, lower case letters "a" and "l") in the "remote file mask" box. If you still do not see a file called .htaccess, you can create a new one in a text editor. Note that it must be saved with the name .htaccess (no other file extension), must be an ASCII text file and must be uploaded via ASCII.

Please note that even if the rest of your site is based on .php, and you would like to use the .php extension for your other error pages, it is probably a good idea to use the .shtml extension for the internal server error.

You may want a different style on your error pages for one of your folders as well. To achieve this, you must use a separate .htaccess file to override the overall site's error pages. Add the following code (remember to include the leading slash preceding the file name) to the .htaccess file that is in the folder you wish to have custom error pages:

ErrorDocument 404 /customfoldername/404.shtml
ErrorDocument 400 /customfoldername/400.shtml
ErrorDocument 401 /customfoldername/401.shtml
ErrorDocument 403 /customfoldername/403.shtml
ErrorDocument 500 /customfoldername/500.shtml

If you do not already have an .htaccess file in the folder you wish to have custom error pages, created one using a text editor. Save the file as .htaccess and upload it via ASCII to the folder you wish to have its own error pages.


I hope all that helps you!


                 \_,^^%---
                  <\_  \ See? It's easy when you know how....
                  >
                  >^^
                 /| 
ejm             | \

For more detailed instructions, please go to Create a Custom 404 Error Page, A List Apart: The Perfect 404, wikipedia: HTTP 404, or wikipedia: List of HTTP status codes.

 
 
 

© llizard 2007

CWC reference pages . ASCII-art . illustrations and gif animations . llinks to ridiculously useless sites . home page