.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 iconsstanding 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.

Leave a comment