How can I create custom Apache error pages?
If you wish to display custom error pages, other than the standard pages that are displayed, you need to set up an extra file to use in the Apache configuration.
You will need root access to your server via SSH (How do I connect to my server over SSH?) to carry out the steps below.
- Log in to your server over SSH. Once logged in, type
su -and provide your root password. - Find the site handle and the top level unix user of the domain you wish to create custom error pages for.
To do this, type the following command:
sitelookup -d yourdomainname.com site_handle,wp_user
This will return something likesitex,adminx, where x will be a number (the number of the site on the server). Remember this information. - Now change to the apache config directory for this site:
cd /etc/httpd/conf/sitex/(substitute sitex with the appropriate number from the previous command's output) - Within this directory, you need to create a config file that Apache will read when it starts up. This config file is going to add settings that will allow you to customise the error pages. Load up your favourite editing program (e.g. Vi) and create a new file called custom_error
To do this using Vi, you would type:
vi custom_error - This file needs to contain the following lines to allow you to make a customised 404 error page:
Alias /error /home/virtual/sitex/fst/var/www/error/
ErrorDocument 404 /error/404.html
You can do this for other Apache error codes. Look at this knowledge base article for information about the different error codes.
Save the changes to that file, and quit the editor program. - Now you need to actually create the directory where your error files will reside. The following commands will do this (remember to replace sitex and adminx with the proper values from your sitelookup command above):
cd /home/virtual/sitex/fst/var/www
mkdir error
chown adminx:adminx error - Now create a custom 404 Error page (or pages for other error codes you defined in your Apache config file) and save it as 404.html. Log in over FTP to the appropriate domain as the site admin user. Navigate to the mainwebsite_html directory, and then back up one directory, so that you can see your /var/www/error directory. Upload your 404.html page there.
- Lastly, you now need to restart the web server so that your custom_error config file is loaded into Apache:
/etc/init.d/httpd restart - Now visit an invalid link in your browser (e.g. www.yourdomainname.com/afdadsfsf) and you should see your custom error page appear.
Note: If your page is too small (less than 512 bytes in size) then Microsoft Internet Explorer will ignore your error page and display its own standard version.
Note: If you have a standard shared hosting account, you do not have root access to the server and cannot perform the majority of these steps. If you want a custom 404 error page (or any other error pages), submit a ticket and we will do everything up to the creation and uploading of your page for you.
Optional ticket rating: Was this article helpful?
Current rating (1059 Votes): ![]() |
|
|---|---|

