I’ve seen this question over at 000webhost.com just now and thought it would be worth posting a short “How to” on enabling and disabling directory listing using .htaccess. If i remember correctly, 000webhost.com does have directory listing activated by default, so when not putting an index.html file in a directory a list of files will be displayed.
Preventing directory listings can be very useful if for example, you have a directory containing important archive files or to prevent viewing of your image directories. Alternatively it can also be useful to enable directory listings if they are not available on your server, for example if you wish to display directory listings of your important ‘.zip’ files. The most common way to turn directory listing on or off is using a .htaccess file. I will show several examples here on this page.
To prevent the webserver from displaying a list of files simply create a .htaccess file (use a simple text editor to do so) and put the following line in it:
Putting this into the .htaccess file tells Apache to prevent directory listings of directories and files within the directory containing the .htaccess file. The ‘*‘ is used as a wildcard, this means it will not display any files. Using wildcards indicates that you can also allow certain file types to display in the list. Let’s say you want everything but .zip archives displayed in the listing, then the line in the .htaccess file should look like this
This tells Apache to display all files in the directory listing except for .zip archives. You can also sort of daisy-chain those file extensions, for example
IndexIgnore *.zip *.jpg *.png
Again, this will tell Apache to display everything except for files ending with .zip, .jpg or .png. Not so hard, is it?
Alternatively, if your server does not allow directory listings and you would like to enable them, create a .htaccess file and put this in it
The above line tells the Apache Web Server to enable directory listing within the directory containing this .htaccess file. You can also reverse this to disable directory listings by replacing the plus sign before the text ‘Indexes’ with a minus sign. e.g. ‘Options -Indexes’.
You can also include a default description for the directory listings that is displayed at the top of the page by placing a file called ‘HEADER’ in the same directory. The contents of this file are displayed before the list of directory contents. You can also include a footer, by creating a file called ‘README’. The contents of this file are displayed after the list of directory contents.