Force Apache directory listing even if DirectoryIndex files are present

5,633

Solution 1

You may leave DirectoryIndex option empty or just turn off dir_module module.

Solution 2

The DirectoryIndex directive can be limited in scope with a Directory block

<Directory /path/to/directory/to/list>
    Options +Indexes +MultiViews
    DirectoryIndex will-never-exist.xyz
</Directory>

This limits the scope to the particular directory rather than your vhost or server etc.

Share:
5,633

Related videos on Youtube

Jake Petroules
Author by

Jake Petroules

Software developer primarily self taught since age 12. Experience in design and development of computer programs, websites, and database systems, 3D graphics, UI design and usability, cross-platform development, and open source software. Co-founded a software company (Petroules Corporation) in college which developed data security software (Silverlock). Active developer in the Open Source Qt Project (qt.io) from late 2012 to early 2018. Key contributor to the Qbs (pronounced "Cubes") build system since its early history. Worked at The Qt Company from late 2015 to early 2018. Working at Apple in the Developer Tools team (Xcode, llbuild, etc.) since February 2018. Studied computer science at Keene State College and took courses at the Massachusetts Institute of Technology and online courses through Stanford University. Specialties: C, C++, Objective-C, Swift, macOS, iOS, Xcode, build automation, cross-platform, qbs, Qt, security &amp; cryptography, UX and UI design

Updated on September 18, 2022

Comments

  • Jake Petroules
    Jake Petroules almost 2 years

    How can I configure Apache to list files in a directory even if an index file is present?

    For example, if I have a directory /var/foo that contains a number of files, and one of those is a directory index (index.html, index.php, etc.), how can I make Apache show the directory listing instead of displaying the contents of index.html, when a user browses to http://example.com/foo/?

    # Directory listing for /var/foo/, mapped to http://example.com/foo/
    ..
    .
    code.c
    readme.pdf
    index.html
    

    I have used the following but I would imagine there's a better way:

    Options +Indexes +MultiViews
    DirectoryIndex will-never-exist.xyz
    
    • Mughil
      Mughil over 12 years
      nice question for an starter
    • Jake Petroules
      Jake Petroules over 12 years
      I'm a frequent Stack Overflow user so I know my way around the network. ;)
  • Jake Petroules
    Jake Petroules over 12 years
    My question was how to disable a DirectoryIndex already in effect, not how to limit scope to a directory...
  • user9517
    user9517 over 12 years
    You should rewrite your question to be clearer about your goal then.
  • Jake Petroules
    Jake Petroules over 12 years
    I think it's worded fairly clear but I'll try to improve it.
  • David Grellscheid
    David Grellscheid about 12 years
    Leaving the option empty doesn't work for me with apache-2.2.14, index.html still gets used.
  • Selivanov Pavel
    Selivanov Pavel about 12 years
    Check your config, it's assigned somewhere. Try to disable module
  • Admin
    Admin over 11 years
    @Selivanov: got the same problem (tried both empty DirectoryIndex and quoted empty string DirectoryIndex "", defined at the root of my VHost). But when I specify a non-existent file (or disable the module), it works so it's not overriden somewhere else (AFAICT).