How to create custom Error Pages?

Error pages come in a variety of forms, but can be customized. Those error documents are web pages designed to give a polite explanation for error conditions. These error conditions generate numbers which are used to refer to the appropriate error condition. Some of the most common
messages are as follows:

Error in Client
400 Bad syntax
403 Forbidden
404 Not Found – Most common

Error in Server
500 Internal Error

You can customize error pages in three ways
By creating a ".htaccess" file:

1. First, create the HTML page you want to use as your error message and upload it
to your home directory.

2.  Next, create a .htaccess file (using NotePad or similar) and add lines which
specify the substitution. Here are three examples of specifying error documents
which will be called for a given error condition (note you can use relative or
absolute addressing):

ErrorDocument 400 http://www.your_domain.com/400.html
ErrorDocument 403 http://www.your_domain.com/403.html
ErrorDocument 404 http://www.your_domain.com/404.html
ErrorDocument 500 http://www.your_domain.com/500.html

Just add these lines to your .htaccess file.

3. Next upload the .htaccess file into your home directory. You will not see it
once uploaded since it gets hidden by the server.

4. Test it out. Go to http://www.your_domain.com/anything_you_want.html
Using a .htaccess file does not work for PHP files. If you want these
errors to work for PHP files too, then use the process below.

By creating error files
You can simply create error pages and name them as follows:

error400.html
error403.html
error404.html
error500.html


Please place these files in the home directory of your domain.

By adding this piece of code in the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.html

Create a file named "errordocument.html" containing your error message
content.

 

Leave a Reply