Skip to content

How to Create a Custom 404 Page in Apache

Cloud Infrastructure Expert
How to Create a Custom 404 Page in Apache

 

 

A custom 404 error page improves user experience by providing a friendly message when a page is not found. This guide will walk you through creating and configuring a custom 404 page in Apache.

1. Create Your Custom 404 Page

First, create the HTML file for your custom 404 error page. For example:

nano /var/www/html/404.html

Add your custom content to the file. Here’s a simple example:




    
    

404 – Page Not Found

Sorry, the page you are looking for does not exist.

Return to Home Page

Save and close the file (press Ctrl+X, then Y, and Enter).

2. Configure Apache to Use the Custom 404 Page

Edit your Apache configuration file or virtual host file to specify the custom 404 error page. For example:

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following directive to the configuration file:


ErrorDocument 404 /404.html
    

Save and close the file (press Ctrl+X, then Y, and Enter).

3. Restart Apache

Apply the changes by restarting Apache:

sudo service apache2 restart

4. Verify Your Custom 404 Page

Test your custom 404 page by navigating to a non-existent URL on your site (e.g., http://your_server_ip/nonexistentpage). You should see your custom 404 page.

5. Troubleshooting

If your custom 404 page is not displaying correctly, check the following:

    • Ensure the 404.html file is in the correct directory.
    • Verify that the ErrorDocument directive is correctly set in your configuration file.
    • Check Apache’s error logs for any issues:
sudo tail -f /var/log/apache2/error.log

6. Customize Further

You can further customize your 404 page by adding styling, links, or even a search bar to help users find what they’re looking for.

Windows VPS Deutschland

Windows VPS España

Windows VPS Nederland

Windows VPS Italia

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Windows RDS (Remote Desktop Services)

Windows VPS

Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.