Support / KnowledgeBase

 
Search the KnowledgeBase Search

Creating custom error pages

  • Applies to: All Service Types

  • Difficulty: Easy

  • Time needed: 5 minutes

  • Tools needed: None

 
  • Applies to: (gs)
    • Difficulty: Medium
    • Time: 20
    • Tools needed: FTP
  • Applies to: All (dv)
    • Difficulty: Medium
    • Time: 20
    • Tools needed: FTP

This article explains how to set up custom error documents for your server. Instead of a plain 404 Not Found or 500 Internal Server Error page, you can show your visitors a customized page that matches your site design.

You should make these pages simple to generate - plain HTML is best. 404 pages especially are needed frequently, and the server will spend a lot of resources if it has to process a complex custom page every time someone generates a 404 request.

Results

Your .htaccess file will override the server default error pages, directing Apache to use custom pages instead.

Using custom error pages

You MUST add a "/" at the beginning of the path to your custom error document. The "/" references the document root of your server (/home/00000/domains/example.com/html/httpdocs by default). The path to your error document should be from the document root, regardless of whether you upload your .htaccess file to the document root directory or to a subdirectory.

That's it! Your change will be instantaneous. You can test your error handling by trying to generate the error yourself. For example, to test a new 404 Not Found page, try visiting http://example.com/this_subfolder_does_not_exist/. Replace example.com with your own domain name. You should see your custom Not Found page.

Common client and server errors

Client Errors

Server Errors

For more information about different types of Status Codes, please see this page at w3.org:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

  1. Create your error pages. The documents can have any name. The example will use not_found.html.
  2. Upload your error pages to your server using FTP. These pages should go inside your html (/home/00000/domains/example.com/html/) directory or a subdirectory. The example will use the subdirectory errors/ (/home/00000/domains/example.com/html/errors/) for error documents.
  3. Upload your error pages to your server using FTP. These pages should go inside your httpdocs directory or a subdirectory. The example will use the subdirectory errors/ for error documents.
  4. Create an .htaccess file with the following lines, or add them to your existing .htaccess file:
  5. Add the following lines to your .htaccess file:

     

    .htaccess
    ErrorDocument 404 /errors/not_found.html
    

    You can add multiple types of custom error documents:

     

    .htaccess
    ErrorDocument 403 /errors/forbidden.html
    ErrorDocument 404 /errors/not_found.html
    

     

  6. Upload your .htaccess file to your html directory via FTP. You can also upload it to a subfolder if you want it to handle error requests only for the subfolder. A subfolder .htaccess file overrides a higher-level one.
  7. Upload your .htaccess file to your httpdocs directory via FTP. You can also upload it to a subfolder if you want it to handle error requests only for the subfolder. A subfolder .htaccess file overrides a higher-level one.
    • 401 Unauthorized - user is not logged into a password-protected area
    • 403 Forbidden - browser does not have permission to perform the requested action
    • 404 Not Found - browser cannot find the requested document on the server
    • 500 Internal Server Error - server was unable to finish processing the request
    • 502 Bad Gateway - server received an invalid response from an upstream server
    • 503 Service Unavailable - server is currently unable to process the request

User Comments

No visitor comments posted. Post a comment
Fields marked with an asterisk(*) are required. Comment on this article
Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue