There are two ways to disable directory browsing feature of Apache web server. However the first method is most practical way as server’s configuration file is typically not modifiable by the user as part of his hosting plan. Most of the hosting provides allow modification of .htaccess file and enable ModRewrite module in the Apache.

The ModRewrite Way

Add the following line towards the end of .htaccess file present in a directory for which you would like to disable directory listing.

Options All -Indexes

However if you have lots of such directories, it may become difficult for you to do this.

The httpd.conf way

If you have access to Apache configuration file (/etc/httpd/conf/httpd.conf), you can search for a line containing the following text.

Options All Indexes FollowSymLinks MultiViews

You need to remove the word “Indexes” from such line and the modified line looks like this.

Options All FollowSymLinks MultiViews

This method is better than the ModRewrite method as this options disables directory listing for all directories in the web site.

Other Way

In a most unfortunate situation where you have no access to .htaccess file and httpd.conf file, you can create a blank index.php file so that Apache shows blank page instead of showing directory listing.