How to stop people from viewing directory content on an Apache web server

Let’s say you have the following files in your root directory:

/public_html/
- FileA.txt
- FileB.jpg
- FileC.doc

By default, Apache will look for an index.htm or index.php to serve the the user if they navigated to:

http://www.example.com/

If those default files do not exist, Apache will end up showing the contents of the directory.  If you want to stop Apache from doing that, you can add an .htaccess file in the directory. The .htaccess file should contain the following line:
Options -Indexes

This will stop users from being able to view contents of directories. This will work for all subdirectories as well.

Leave a Reply

*