Would you like to learn how to redirect the 404 error to a specific URL on the Apache server? In this tutorial, we are going to configure the Apache server to redirect the 404 error to a specific page.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41

In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache - Redirect the error 404

Install the Apache server.

Copy to Clipboard

Edit the Apache configuration file for the website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Change the URL to reflect your needs.

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect the 404 errors to a specific URL.

From a remote Linux computer, try to access a page that does not exist.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the 404 error was redirected to a specific URL using a 302 code.

Congratulations! You redirected the 404 errors on the Apache server.

Tutorial Apache - Redirect the error 404 using HTACCESS

Install the Apache server.

Copy to Clipboard

Edit the Apache configuration file.

Copy to Clipboard

Add the following lines at the end of the file.

Copy to Clipboard

Create an HTACCESS file on the website directory.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Configure the correct file permission.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect the 404 errors to a specific URL.

From a remote Linux computer, try to access a page that does not exist.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the 404 error was redirected to a specific URL using a 302 code.

Congratulations! You redirected the 404 errors on the Apache server using an HTACCESS file.