Ultra Web Hosting Docs

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:

Customizing Error Pages in cPanel

  1. Log into cPanel.
  2. In the Advanced section, click Error Pages.
  3. Select the domain you want to customize error pages for.
  4. Click on the error code you want to customize (e.g., 404).
  5. 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.
  6. 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>
Tip Include your website's navigation, a search bar, and links to popular pages on your custom 404 page. This gives visitors a way to recover and stay on your site instead of leaving.

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.

Note When using 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

Warning Make sure your custom error page itself does not trigger another error (e.g., a missing image or broken include). Test your error pages by visiting a URL that does not exist on your website.