Would you like to learn how to disable the directory listing on the Apache server? In this tutorial, we are going to configure the Apache server to block the directory browsing feature.

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

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 – Disable the directory listing

Install the Apache server.

Copy to Clipboard

Disable the Apache module responsible for the directory listing.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

As a test, create a directory without an index file.

Copy to Clipboard

Try to access the directory without the index file.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the directory listing feature was disabled on the entire Apache server.

From a remote computer, open the browser and try to access a directory of the Apache server.

• http://192.168.2.222/test

The Apache server will display an error message.

Here is the result, before our configuration.

Apache - Disable directory browsing

Here is the result, after our configuration.

Apache - Disable directory listing

Congratulations! You configured the Apache server to disable the directory browsing feature.

Tutorial Apache – Disable file listing on a specific directory

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 directory you want to protect.

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

As a test, create a directory without an index file.

Copy to Clipboard

Try to access the directory without the index file.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the directory listing feature was disabled on a directory.

From a remote computer, open the browser and try to access a directory of the Apache server.

• http://192.168.2.222/test

The Apache server will deny access and display an error message.

Here is the result, before our configuration.

Apache - Disable directory browsing

Here is the result, after our configuration.

Apache - Disable file listing

Congratulations! You disabled the directory listing on the Apache server.

Tutorial Apache – Disable directory listing 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

As a test, create a directory without an index file.

Copy to Clipboard

Try to access the directory without the index file.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the directory listing feature was disabled on a directory.

From a remote computer, open the browser and try to access a directory of the Apache server.

• http://192.168.2.222/test

The Apache server will deny access and display an error message.

Here is the result, before our configuration.

Apache - Disable directory browsing

Here is the result, after our configuration.

Apache - Disable file listing

Congratulations! You disabled the directory listing on the Apache server.