Celebrate Our 22nd Anniversary with Huge Savings! Up to 70% Off

How to Set a Custom 404 Page With .htaccess?

A custom 404 page is essential for a positive user experience. Instead of a generic error message, it guides visitors to a helpful page if they try to access content that doesn't exist. This can be easily achieved using an .htaccess file. If your website is hosted on a cPanel server, implementing a custom 404 page is a straightforward process. This guide will provide a step-by-step guide on how to configure your cPanel 404 page using the .htaccess file.

 

Method 1: Create a Custom HTML 404 Page

If you want a fully designed 404 page with branding, links, and styling, follow these steps:

 

Steps to Create a Custom 404 Page

1. Open a text editor (Notepad, VS Code, or any HTML editor).

2. Add your custom HTML code there for the 404 page. You can add an attractive 404 image, links to your home page, search page, and more.

Here is a simple example of a custom HTML code.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>404 - Page Not Found</title>
    <style>
        body { font-family: Arial, sans-serif; text-align: center; background-color: #f8f9fa; color: #333; padding: 50px; }
        .container { max-width: 600px; margin: auto; }
        h1 { font-size: 48px; margin-bottom: 10px; }
        p { font-size: 18px; margin-bottom: 20px; }
        .btn { display: inline-block; padding: 10px 20px; font-size: 16px; color: #fff; background-color: #007bff; text-decoration: none; border-radius: 5px; margin: 5px; }
        .btn:hover { background-color: #0056b3; }
    </style>
</head>
<body>
    <div class="container">
        <h1>Oops! Page Not Found</h1>
        <p>Sorry, the page you are looking for doesn't exist or has been moved.</p>
        <a href="/" class="btn">Go to Home</a>
        <a href="/search" class="btn">Search</a>
    </div>
</body>
</html>
 

3. Save the file as 404.html.

 

Steps to Add This Page to cPanel

1. Login into your cPanel account provided by your web hosting provider and upload the file to your public_html folder using cPanel.

2. Go to File Manager under the Files section.

 

 

3. Navigate to the public_html folder.

4. Look for the .htaccess file.

5. Right-click on .htaccess and select Edit.

 

 

 

6. At the end of the .htaccess file, add this line:

 
ErrorDocument 404 /404.html
 

7. Click Save Changes and close the editor.

 

 

8. Open a web browser and try visiting a non-existent page, like:

 
yourdomain.com/randompage
 

9. If everything is set up correctly, your custom cPanel 404 page will appear as shown in the screenshot below.

 

 

Method 2: Set a Simple 404 Page in .htaccess

If you don’t want to create a separate 404.html file, you can display a simple error message directly from .htaccess.

 

Steps to Add a Simple 404 Message

1. Login into your cPanel account provided by your web hosting provider

2. Go to File Manager under the Files section.

 

 

3. Navigate to the public_html folder.

4. Look for the .htaccess file.

5. Right-click on .htaccess and select Edit.

 

 

6. At the end of the .htaccess file, add this line:

 
ErrorDocument 404 "<H1>Page not found</H1>"
 

7. Click Save Changes (top-right corner).

 

 

8. If everything is set up correctly, you will see a plain "Page not found" message instead of the default server error page.

Setting up a custom 404 Page .htaccess error page helps improve user experience and keeps visitors engaged. If you prefer a branded and professional-looking page with navigation options, Method 1 is the best choice, as it allows you to design a custom HTML file. On the other hand, if you want a quick and simple solution without creating an extra file, Method 2 is the way to go, as it directly displays a basic message using the .htaccess file. 

 
 

Was this answer helpful?

« Back