How To Create Custom 404 Page in Apache

custom 404 page Techhyme

Did you know that Apache, one of the most widely used web servers, provides a simple way to configure custom 404 error pages for your website? With the ErrorDocument directive, you can easily set up a personalized error page in Apache without any complex coding. In this article, we will guide you through the process of creating a custom 404 page in Apache.

Moreover, you can apply these steps to configure custom error pages for various other HTTP status codes such as 403, 500, 502, and more.

Steps to Configure Custom 404 Error Page:

1. Open .htaccess file or Virtual Host Configuration File

Locate and open the `.htaccess` file in your website’s root folder. This file is often found at `/var/www/html/`. You can use a text editor like Vim:

sudo nano /var/www/html/.htaccess

If you have configured virtual hosts, you can alternatively open your virtual host configuration file. For example, for a domain named example.com:

sudo nano /etc/apache2/sites-enabled/example.com

You can also open the default virtual host configuration file:

sudo nano /etc/apache2/sites-enabled/000-default.com

2. Configure 404 Error Page

Add the following line to the `.htaccess` file:

ErrorDocument 404 /error404.html

In this line, the error response code is set to 404, and the custom page `error404.html` is specified to be served when this error occurs. You can adapt this line to configure error pages for other response codes like 500, 502, 403, etc.

If you are working with a virtual host file, include the above line within the `<VirtualHost>` tags:

<VirtualHost>
   ...
   ErrorDocument 404 /error404.html
   ...
</VirtualHost>

3. Create the 404 Error Page

Create a custom error page named `error404.html` using a text editor or a website builder such as Squarespace, WordPress, or Wix. Customize this page to suit the design and content preferences of your website.

4. Restart Apache Server

Once you have configured the custom error page, restart the Apache server to apply the changes:

sudo service apache2 restart

This will ensure that the new custom 404 error page is now active on your website.

By following these steps, you can easily create and implement a personalized 404 error page for your Apache web server. Feel free to use a similar approach to configure custom pages for other HTTP status codes, providing a more user-friendly and brand-consistent experience for your website visitors.

You may also like:

Related Posts

Leave a Reply