IndexIgnore * 或选项 -Indexes [英] IndexIgnore * or Options -Indexes
问题描述
我一直使用 Options -Indexes
通过 .htaccess 禁用目录列表.但是,我看到有人使用 IndexIgnore *
代替.有什么不同?哪个比另一个更好?
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?
推荐答案
IndexIgnore
指令 是一种模式,其中Indexes
打开 的目录中的文件不会出现在如果它们与模式匹配,则自动索引.
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.
例如,我们有一个目录 foo
,在该目录中,我们有一个 .htaccess
文件和 3 个文件 a
、b
和 c
.
Say for example, we have a directory, foo
, and inside that directory, we have an .htaccess
file, and 3 files, a
, b
, and c
.
如果在 htaccess 文件中有 Options -Indexes
,那么通过访问 http://mysite.com/foo/
,我会得到 403 Forbidden 响应,因为没有索引文件(index.html、index.php等),自动索引通过-Indexes
关闭.
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
.
如果在 htaccess 文件中有 IndexIgnore b
,那么通过访问 http://mysite.com/foo/
,我会得到一个自动索引响应列出文件,a
和 c
.b
文件将丢失,因为它已被忽略.如果我们在 htaccess 文件中有 IndexIgnore *
,然后我们转到 http://mysite.com/foo/
,我们将得到一个自动索引文件为空,因为所有文件都已被忽略.
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.
至于哪个更好,这取决于您想要什么.他们从根本上做两件不同的事情.你想要自动索引吗?如果没有,请将其关闭 Options -Indexes
.如果是这样,请保持打开状态.如果您不希望某些内容显示在自动索引中,请使用 IndexIgnore
.
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
.
这篇关于IndexIgnore * 或选项 -Indexes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!