How to Set up Custom Error Pages with WHM?
introduction
You can redirect customers to custom-made HTML pages whenever they see a server error. An example is a visitor tries to access a web page that does not exist anymore. In this case, they will be redirected to a special error page that you have created for the 404 error.
WHM (Web Host Manager) allows you to set these custom error pages throughout all of your cPanel server(s).
Why Use Custom Error Pages?
Server error messages (such as the default 404 Not Found) tend to be generic and confusing for the visitor. The custom error pages are more helpful, and they create a better user experience as they offer useful information about the site, brand consistency, and give a navigation link to the main site.
This feature helps avoid the situation where users will leave the site completely when they come across a broken link or server problem.
First Setup: Create Directory and Alias
To assign the custom pages, you have to first create a special directory on the server and set an alias pointing to it within the Apache configuration file (/usr/local/apache/conf/httpd.conf).
- Log in to WHM with Root Access
Begin by entering your WHM panel account with full root account credentials.
- Click on Server Configuration and Terminal
In the navigation menu, select the Server Configuration option. Next, click on Terminal. This will start up the command-line interface, similar to a direct SSH session.
- Create a Storage Directory
Enter the following command line instruction to create a folder in /usr/local/apache. This new place will be where you will store your custom error documents.
- mkdir /usr/local/apache/errorpages
In this case, the new folder is called errorpages. After the directory is established, you may go on to define the custom pages and set up the alias.
Steps to Set Up/Add Custom Error Pages
Once you have created the destination directory, you must inform Apache where to find the custom error pages using the Include Editor.
- Select Service Configuration
On the navigation menu, find and select the ‘Service Configuration’ option.
- Click on Apache setup.
Under the Service Configuration section, click on ‘Apache Configuration’.
- Click on Include Editor
Then, click the Include Editor link. This tool enables you to safely inject global configuration commands into the Apache settings.
- Configure Pre Virtualhost Include
You need to target the configuration that affects all virtual hosts.
Select Section: Choose Pre Virtualhost Include area and choose All Versions.
Enter Configuration: Paste or type the code in the Global text field as follows:
Alias /errorfolder /usr/local/apache/errorpages/
ErrorDocument 400 /errorfolder/400.shtml
ErrorDocument 401 /errorfolder/401.shtml
ErrorDocument 403 /errorfolder/403.shtml
ErrorDocument 404 /errorfolder/404.shtml
ErrorDocument 500 /errorfolder/500.shtml
- Update and Restart Apache
The Apache server must be reloaded for the changes to take effect.
Click Update: Click the Update button to save the configuration changes.
Click Restart: The next step is to click on Restart Apache.
Once the server restarts, any HTML pages you upload to the designated errorpages (or alias) folder will serve as the custom error pages for all the websites operating on your WHM/cPanel server.
Conclusion
The custom error page setup using the WHM interface is a solid way to enhance the look and functionality of your error page handling server. With the use of the directory, an alias, and an adjustment of the Apache configuration, you successfully implement these custom redirects for all users.
Frequently Asked Questions
Why create an Alias for the directory?
Creating an Alias (like /errorfolder) allows the Apache web server to understand the custom directory path without exposing the actual file system path (/usr/local/apache/errorpages/).
What file types should the custom error pages be?
The custom error pages should be standard HTML files; the example uses the .shtml extension, which allows for server-side includes.
What is the functionality of the ErrorDocument 404 directive?
This command is specifically telling the Apache web server to be able to serve the file located at /errorfolder/404.shtml whenever a 404 (Not Found) HTTP error occurs.
What WHM tool is used to insert the Alias code into the configuration?
The Include Editor tool, found under Service Configuration $\rightarrow$ Apache Configuration, is used to inject the code into the global server configuration.
Why is it necessary to restart the Apache server?
Restarting the Apache server is required since it needs a complete reload of the httpd.conf configuration file to recognize and apply the new Alias and ErrorDocument directives.