Disabling the directory listings
It could be quite useful to prevent directory listings if, for instance, there is a directory that contains important achieve files i.e, ‘.zip’ or for preventing your directories of images from viewing. Alternatively, it’s also useful for directory listings to enable in case they aren’t available on the web server, for example, for displaying directory listings of the ‘.zip’ files that are important.
For preventing the directory listings, you need to make an .htaccess file and follow the guidance and main instructions that include the text below.
Through the lines above Apache Web Server will get instruction for preventing directory listings for files and directories in the directory that contains the file .htaccess. In the above code ‘*’ is a representation of wildcard that means no files will be displayed by it. Also, the listings of any specific files types only can be prevented, for example, listings of only ‘.html’ files can be shown but not the ‘.zip’ files.
For preventing ‘.zip’ files listings, you need to make an .htaccess file and follow the guidance and main instructions that include the code below.
Code above will instruct Apache Web Server to do listings of all the files except the ones ending with extension ‘.zip’.
For preventing the listings of more than one file types, you need to make an .htaccess file and follow the guidance and main instructions that include the code below.
IndexIgnore *.zip *.jpg *.gif
From the above code, Apache Web Server will get the instruction to do listings of all files but not the ones that end with ‘.jpg’, ‘.gif’, or ‘.zip’.
Alternatively, if directory listings are not allowed by your server and you want them to be enabled; you need to make an .htaccess file by following the guidance and main instructions that include the text given below.
From the above lines, Apache Web Server will get the instruction for enabling directory listings in the directory that contains the .htaccess file. This can also be reversed for disabling directory listings just with a replacement of the sign plus (+) before ‘Indexes’ by a minus (-) sign. Example, ‘Options –Indexes’.
A description can also be included by default for directory listings which is shown at page top by adding a file named ‘HEADER’ in that same directory. This file’s contents are shown before directory contents list. Also, a footer can be included by making a file named ‘README’. This file’s contents are shown after directory contents list.