How to create error pages?

FRONTPAGE WARNING: Any modifications to your .htaccess file can corrupt your extensions and render your site inaccessible. A backup copy of your .htaccess file should be made before you attempt any changes.

Intro: The .htaccess file is an ASCII text document that can be placed in any directory on your site. It can be used to control access to files and directories, and customize some server operation in your site. A .htaccess file can be created in any word processor but must be saved as text only. You must use FTP software in ASCII mode to upload or edit your .htaccess file. For the examples provided here, place the .htaccess file in your root directory.

FRONTPAGE WARNING: FrontPage sites have a .htaccess file in the root directory that is created when the FrontPage extensions are installed. FrontPage users should proceed with caution and make a backup copy of their .htaccess file before making any changes. Incorrect changes to your .htaccess file can result in your site being unreachable.

  1. Open a new notepad document in Windows or any plain text editing software.
  2. Add in to the text "ErrorDocument 404 /notfound.html"



    After "ErrorDocument" specify the error code, followed by a space, and then the path and filename of the .html file you would like to be displayed when the specified error is generated.
  3. Save this file as .htaccess, even though Windows will automaticly add the ."txt" extension to it, this doesn't matter.
  4. After you have done this log into your control panel and click on Files.
  5. Browse through the dir until you get to path "var/www/html"
  6. Scroll down to the bottom and click on "Browse" in the "Upload file" input tag and browse where you saved your .htaccess file as in step 3.

    On the "And save as" tag please put in ".htaccess" and click on "Upload"
  7. Thats it! Now you need to create your 404 or error page and upload it to your html dir and make sure it is to the path you put on step 1. And test it on your domain.

Here are some other things you can add to your .htaccess file:

Denying User Access

Add the following to the .htaccess file:


order allow,deny
deny from 128.23.45.
deny from 207.158.255.213
allow from all

This is an example of a .htaccess file that will block access to your site to anyone who is coming from any IP address beginning with 128.23.45 and from the specific IP address 207.158.255.213 . By specifying only part of an IP address, and ending the partial IP address with a period, all sub-addresses coming from the specified IP address block will be blocked. You must use the IP addresses to block access, use of domain names is not supported.


Redirect a Machine Name

FRONTPAGE WARNING: Adding this to your .htaccess will not allow you to publish with FrontPage. You need to keep a copy of your original .htaccess file to replace the modified file when making changes to the site

Add the following to the .htaccess file:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for machine.domain-name.net
RewriteCond %{HTTP_HOST} machine.domain-name.net$
RewriteCond %{REQUEST_URI} !machine/
RewriteRule ^(.*)$ machine/$1

This will redirect requests for the machine name machine.domain-name.net to the directory machine on the site domain-name.net .


Different Default Home Page
Add the following to the .htaccess file:

DirectoryIndex filename.html

Then a request for http://domain-name.net/ would return http://domain-name.net/filename.html if it exists, or would list the directory if it did not exist.

To automatically run a cgi script, add the following to the .htaccess file:

DirectoryIndex /cgi-bin/pdesk.cgi

This would cause the CGI script /cgi-bin/pdesk.cgi to be executed.

If you place your .htaccess file containing the DirectoryIndex specification in the root directory of your site, it will apply for all sub-directories at your site.


Preventing People from Linking to Your Images
Add the following to the .htaccess file:

# Rewrite Rule for images
RewriteCond %{HTTP_REFERER}
RewriteRule ^(.*)$ http://

You would replace the above with the domain name and path of the page that is referring to your domain. For example: www.their-isp.net/users/mypage/

The RewriteCond directive states that if the {HTTP_REFERER} matches the URL that follows, then use the RewriteRule directive. The RewriteRule directive will redirect any reference back to the

Was this answer helpful?

 Print this Article

Also Read

Using Server-Side Includes (SSI)

The Apache web server has a number of configuration options that are available to the server...

Outlook Express Error Code : 0x800CCC0E While Sending Email

Problem: While sending email message outlook express shows error message like: The connection...

553 SMTP Relaying Denied

This error is caused for one of two reasons: You are attempting to send email to a domain...

Using mySQL

Overview of MySQL database. Creating/Deleting/Editing Databases and Users Connecting...

Use of .htaccess file

The Apache web server has a number of configuration options that are available to the server...