The Apache web server looks for index.html file to be present in the default “DocumentRoot” directory (by default /var/www/html directory). This file name is controlled by a directive named “DirectoryIndex”. In Apache configuration file, the default value for this directive is index.html. If index.html file is not present in the “DocumentRoot” directory, then the server will return the directory contents of this directory. This article shows how that directory listing can be disabled in Apache web server.
The Options Directive
The configuration file of Apache web server in Red Hat Enterprise Linux 5.6 is /etc/httpd/conf/httpd.conf. The configuration of directories is controlled by the directive named "Options". This is a part of the configuration file that we are concerned with:
# This should be changed to whatever you set DocumentRoot to.
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
# The Options directive is both complicated and important. Please see
# for more information.
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
# Controls who can get stuff from this server.
Allow from all
The "<Directory> " and "</Directory> " enclose a set of directives that apply to a particular directory. In this file, the corresponding directives apply to "/var/www/html" directory. The "Options" directive controls what features are available for a particular directory. Out of these options, "Indexes" defines that in the absence of DirectoryIndex (e.g. index.html) a formatted listing of the directory will be returned.
So to disable the directory listing, you just need to remove “Indexes” from Options directive:
This will disable the directory listing for Apache web server.