- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.0
- » Web Applications
- » PHP and Coding
Creating custom error pages
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.
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
- Create your error pages. The documents can have any name. The example will use not_found.html.
- 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.
- 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.
- Create an .htaccess file with the following lines, or add them to your existing .htaccess file:
-
Add the following lines to your .htaccess file:
.htaccess
ErrorDocument 404 /errors/not_found.html
You can add multiple types of custom error documents:
.htaccessErrorDocument 403 /errors/forbidden.html ErrorDocument 404 /errors/not_found.html
- 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.
-
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