How to Create Custom Error Documents

One way you can increase your brand’s awareness while also providing failure-proof navigation for your customers is to make custom error documents. Users on your dedicated server may decide to use their own error documents for individual websites, but most will leave the default error documents the system administrator selects. If the sysadmin does not choose an error doc, the default Apache error page (such as “404 Not Found”) will be shown, and you will miss a golden opportunity.

An error document is essentially just a normal web page. All you have to do is tell Apache to redirect to that page when an error occurs. To set global error documents for all Apache websites, you will need to edit your Apache configuration file (/etc/httpd/conf/httpd.conf in CentOS).

To set global error documents, enter the following directives, replacing the URL or path with ones on your server:

ErrorDocument 500 http://yourdomain.tld/edocs/500-error.html
ErrorDocument 404 http://yourdomain.tld/edocs/404-error.html
ErrorDocument 403 http://yourdomain.tld/edocs/403-error.html
ErrorDocument 401 /local/path/401-error.html

You can redirect an error code to any page or site you want, even to a script, but if you create custom error docs, you can guide users to the right places and also promote whatever brand or services you have associated with your server. For virtual hosts, you can use the vhost configuration files to set error documents, and individual website owners can use .htaccess files to enter the exact same directives, as long as the AllowOverride directive is enabled. For more information about Apache custom error responses, see the official documentation.