Example How To Disable Apache Directory Listing

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.

<Directory "/var/www/html">

# 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
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# 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
AllowOverride None

# Controls who can get stuff from this server.
Order allow,deny
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:

Options FollowSymLinks

This will disable the directory listing for Apache web server.

Bobbin Zachariah 4:19 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.