Custom Error Pages
Replace the default server error pages with your own custom designs. Give visitors a helpful, branded experience even when something goes wrong.
What Are Error Pages?
When a visitor encounters a problem on your website, the server returns an HTTP error code and displays an error page. The most common error codes are:
- 400 Bad Request — The server could not understand the request due to malformed syntax.
- 401 Unauthorized — The page requires authentication and the visitor has not provided valid credentials.
- 403 Forbidden — The server understood the request but refuses to authorize it. Usually a permissions issue.
- 404 Not Found — The requested page does not exist. This is the most common error visitors will encounter.
- 500 Internal Server Error — A general server-side error, often caused by a misconfigured
.htaccessfile or a PHP script error.
Customizing Error Pages in cPanel
- Log into cPanel.
- In the Advanced section, click Error Pages.
- Select the domain you want to customize error pages for.
- Click on the error code you want to customize (e.g., 404).
- Enter your custom HTML in the editor. You can use the following server-side variables:
— The error code number.— The URL that caused the error.— Your domain name.— The server name.
- Click Save.
Creating a Custom 404 Page
A good 404 page helps visitors find what they were looking for. Here is an example you can customize:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px 20px;
background: #f5f5f5;
color: #333;
}
h1 { font-size: 48px; margin-bottom: 10px; }
p { font-size: 18px; color: #666; }
a { color: #0066cc; }
</style>
</head>
<body>
<h1>404</h1>
<p>The page you requested could not be found.</p>
<p><a href="/">Go back to the homepage</a></p>
</body>
</html>
Using .htaccess for Custom Error Pages
For more control, you can define custom error pages using your .htaccess file. This approach lets you use a full PHP or HTML file as your error page.
Add the following lines to the .htaccess file in your public_html directory:
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
Then create the corresponding files in a public_html/errors/ directory.
ErrorDocument with a file path, the path is relative to your document root. Make sure the error page file actually exists at that path, or you will create a redirect loop.
Using a PHP File as an Error Page
You can use a PHP file as your error page to dynamically generate content or match your site's design:
ErrorDocument 404 /404.php
In your 404.php file, make sure to set the correct HTTP status code at the top:
<?php
http_response_code(404);
?>
<!-- Your custom 404 page HTML here -->
Best Practices
- Match your site's design — Error pages should look like the rest of your website so visitors know they are still on the right site.
- Provide navigation — Include links to your homepage, popular pages, or a site map.
- Add a search box — If your site has search functionality, include it on your error page.
- Keep it simple — Avoid loading heavy resources (large images, external scripts) that might also fail to load.
- Use friendly language — Avoid technical jargon. A simple "We couldn't find that page" is better than "HTTP 404 Not Found Error".