I've always used Options -Indexes
to disable directory listing through .htaccess. However, I have seen people using IndexIgnore *
instead. What's the difference? Which is better than the other?
The IndexIgnore
directive is a pattern where files in a directory that has Indexes
turned on won't show up in the auto-index if they match the pattern.
Say for example, we have a directory, foo
, and inside that directory, we have an .htaccess
file, and 3 files, a
, b
, and c
.
If in the htaccess file there is Options -Indexes
, then by going to http://mysite.com/foo/
, I will get a 403 Forbidden response, because there is no index file (index.html, index.php, etc) and auto-index is turned off via -Indexes
.
If in the htaccess file there is IndexIgnore b
, then by going to http://mysite.com/foo/
, I will get an auto-index response listing the files, a
and c
. The b
file will be missing because it has been ignored. If we have IndexIgnore *
in the htaccess file instead, and we go to http://mysite.com/foo/
, we'll get an auto-index file that is blank, since all files have been ignored.
As for which is better, it depends on what you want. They do fundamentally two different things. Do you want auto-indexes? If not, turn it off Options -Indexes
. If so, leave it on. If you don't want some things to show up in an auto-index, then use IndexIgnore
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With