Today I will show you how easy it is to allow or deny a visitor to your website to view a directory listing if a default webpage is not available. This is controlled in a single file called .htaccess. Continue reading if you want to know more.
To begin, what I’ll be showing you requires the two following prerequisites:
- Your website must be on a server running Apache
- Apache needs to be setup to allow .htaccess overrides
Both of the above conditions need to exist, otherwise the following information will not work.
In the root directory of your website, you need a file named .htaccess. If one currently exists, copy it to your local computer via FTP for editing. Otherwise, create one locally. Open the file in a simple text editor such as Notepad or VIM. Edit the file with one of the following lines as needed.
Change Listing style
(This disables Fancy Directory listing.)
Ignore files with specific extension
IndexIgnore *.zip *.txt
Seriously…it’s that easy. If you edit the .htaccess file in your root directory, then all sub-directories are affected. However, you can customize a specific subdirectory by creating and adding a new .htaccess file to that specific directory.
If you want to know more about .htaccess files, please visit the Apache.org website.