Consider you have a bunch of files in your directory called uploads, it may have zip files, jpg files, png files, pdf files, doc files and so on. In such case when someone enters the path in the browser ex: http://www.geeks.gallery/uploads/, the entire list of files gets listed. So one can easily access your files. In certain situation, you may have to avoid listing those important files for others.
In order to deny directory listing, you can simply add a line in your .htaccess file.
You will get a result as
If in case, you have to enable the listing of files in the directory, do this
If you don’t wish the user to see Access Denied message, and also you wish to hide the files from listing, in that case you can use the following code
The result will be
If you want only a single zip file to be hidden, we can also do that.To do so
And we can hide all zip files in a directory by
We can also hide zip,pdf and doc files and show other formats of file at a time.
IndexIgnore *.zip *.doc *.pdf
Thanks for Reading.
Latest posts by Nagarajan (see all)