.htaccess: Directory Listing — Enable Web Directory Browsing & Indexing

One of the best things I love Apache web server is that it instantly enables you to share files and resources via plain web directory index listing without having to spend time making any fancy web pages to serve them.

However, there are times when you need to hide things out. To disable web directory listing, you need just a simple directive in .htaccess of that directory. Insert this line to disable apache files listing for this directory and all directories or folders underneath it:

Options -Indexes

However, you may need to specifically enable file indexing for some directory under the parent directory. Just override the above .htaccess directive by creating another .htaccess in the child directory and write:

Options +Indexes
Enable fancy indexing

Fancy indexing is a bit more sophisticated than plain indexing in that it explicitly presents file types and image icons (icons are small images that boost user experience by conveying the idea very intuitively, such as these flag icons standing for countries) for easy discrimination. You can enable fancy indexing for a directory listing by adding an additional directive:

Options +Indexes
# adding fancy directory indexing
IndexOptions +FancyIndexing

# is the comment symbol for .htaccess directives.

Exclude certain files from indexing

There might be confidential files you want to exclude from the indexing and stop them from being shown to visitors. The directive below helps you achieve this task:

IndexIgnore *.jpg *.gif readme.txt

Very straightforward and self-explaining, just modify it for your own situations.

3 thoughts on “.htaccess: Directory Listing — Enable Web Directory Browsing & Indexing”

  1. Thanks for the tips — just what I needed, since GoDaddy.com has fancy indexing disabled by default. This allows me to activated it on a per-directory basis.

  2. Wow, 4 years later your tips paid off for me big time. My web host broke something overnight on the server and told me I cannot directory browse my image folder. I used your tips and added the “Options +Indexes” command to a second .htaccess file and put it into my image folder which hangs off my main directory, and that fixed it. 2 hours on the phone with Verio and I gave up. Searched and found your blog entry and 5 minutes later i solved it. thanks!

Comments are closed.

Scroll to Top