It is highly beneficial to configure custom error documents that are displayed when encountering HTTP errors like a 404 (page not found), 403 (forbidden), or 500 (internal server error). By setting up these customized error pages, you can provide a more personalized and informative experience for your website visitors when they come across any of these errors.
It not only enhances the overall user experience but also helps to maintain a professional and user-friendly image for your website. By taking this proactive step, you can effectively communicate and guide your visitors through any errors they might encounter, ensuring a smoother and more engaging browsing experience.
This article will explain the process of creating and testing these error pages.
Related Articles
Change Directory Index of Page
500 Internal Server Error
Edit .htaccess
- Log into cPanel or SSH into your server
- Verify that the custom HTML files already exist on the server
- Access the document root of the site
- Edit the .htaccess file for the site
TIP: If a .htaccess is not present, show hidden files in File Manager. - Add the following code using the respective file names for the replacement 404 and 403 HTML files
ErrorDocument 403 custom403.html ErrorDocument 404 custom404.html
REPLACE: custom403.html and custom404.html with the actual file names.
TIP: Other status codes, such as a 500 error, can also have custom pages. - Save the change to the .htaccess file
- Attempt to confirm the custom ErrorDocument is working by viewing an error of the same type
- To generate a 404 error, visit a URL that does not exist on the server
- To generate a 403 error, create a temporary file named 403test.php with the following content
<?php header("HTTP/1.0 403 Forbidden"); ?>
- Visit the URL in the browser to verify custom ErrorDocument is working
-