Q. I’m using Apache 2 under Linux. How do I enable apache file and directory indexing? Currently it is disabled and I would like to enable the same for /pdfs/ directory (http://domain.com/pdfs).

A. Under Apache web server automatic index generation is enabled with using Options +Indexes or Options Indexes directive.

If a URL which maps to a directory is requested, and there is no DirectoryIndex (e.g., index.html) in that directory, then mod_autoindex will return a formatted listing of the directory.

Option # 1: Using Apache config file

Add directory option to Apache configuration file /etc/httpd/httpd.conf or /etc/apache2/apache2.conf:
# vi /etc/apache2/apache2.conf
Add following code:
<Directory /var/www/domain.com/pdfs>
Options Indexes FollowSymLinks

Save and close the file. Restart Apache:
# /etc/init.d/httpd restart
# /etc/init.d/apache2 restart

Option #2: Using .htaccess Files with Apache

You can place config line Options Indexes in .htaccess file. Make sure .htaccess file support is enabled.
Change directory to pdfs
$ cd pdfs
Open .htaccess file
$ vi .htaccess
Append following apache directive:
Options Indexes
Save and close the file.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • LinuxFreaker Oct 22, 2009 @ 7:37

    Make sure .htaccess file support is enabled.

    How to check if thats there in apache Distros.
    What is the aim of “Using .htaccess Files with Apache”?

  • M kazzaz Feb 11, 2012 @ 8:21

    I did so but i still have the Forbidden Error message I can read the files but i can’t list them

  • sarah robert Sep 11, 2012 @ 14:15

    I have the same problème
    can you help me?
    i tried with options indexes// options -indexes//options +indexes//
    i have dedecated server

  • Mike Schinkel Sep 29, 2012 @ 2:25

    This is wrong for


    Options Indexes

    It should be :

    Options +Indexes

  • alds Jun 27, 2014 @ 3:17

    Thanks for this article and your website in general. Your site has been my go-to resource for linux commands. I like the way you structure your articles so that they appear cookbook-style where you describe a scenario and provide the solution concisely. There is no need to read through long articles for a particular command like what other sites do. Keep up the good work!

  • Shamal Sandeep Oct 24, 2014 @ 2:25

    Thanks dude! Just worked like a charm. This is what I was really expected!

  • mr. Robot Jan 19, 2017 @ 10:58

    if u got PERMISSION DENIED, it’s probably because of SElinux, u can do this
    setenforce 1, so it will change SElinux status in Permissive
    [ NOTE : I suggest this comand just to be sure that the problem with is SELinux ]
    see more for info man SELinux httpd … u can find something maybe :)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum