i007.cc

i007.cc

优先队列-降维打击

禁止apache显示目录索引的常见方法(apache禁止列目录)

下面说下禁止禁止Apache显示目录索引的常见的3种方法。要实现禁止Apache显示目录索引,只需将Option中的Indexes去掉即可,具体方法看下面说明

禁止Apache显示目录索引,禁止Apache显示目录结构列表,禁止Apache浏览目录,这是网上提问比较多的,其实都是一个意思。下面说下禁止禁止Apache显示目录索引的常见的3种方法。
要实现禁止Apache显示目录索引,只需将 Option 中的 Indexes 去掉即可。

1)修改目录配置:

复制代码代码如下:
<Directory “D:/Apache/blog.phpha.com”>
Options Indexes FollowSymLinks # 修改为: Options  FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

只需要将上面代码中的 Indexes 去掉,就可以禁止 Apache 显示该目录结构。用户就不会看到该目录下的文件和子目录列表了。Indexes 的作用就是当该目录下没有 index.html 文件时,就显示目录结构,去掉 Indexes ,Apache 就不会显示该目录的列表了。

2)修改Apache配置文件[httpd.conf]

搜索“Options Indexes FollowSymLinks”,修改为“Options -Indexes FollowSymLinks”即可。
在Options Indexes FollowSymLinks在Indexes前面加上 – 符号。备注:在Indexes前,加 + 代表允许目录浏览;加 – 代表禁止目录浏览。这样的话就属于整个Apache禁止目录浏览了。
如果是配置虚拟机,则如下:

复制代码代码如下:
<VirtualHost *>
<Directory “../vhosts/blog.phpha.com”>
Options -Indexes FollowSymLinks # 修改为 -Indexes 即可
</Directory>
ServerAdmin [email protected]
DocumentRoot “../vhosts/blog.phpha.com”
ServerName shopex:80
ServerAlias blog.phpha.com
ErrorLog logs/blog.phpha.com-error_log
</VirtualHost>

3)通过.htaccess文件

可以在根目录新建或修改 .htaccess 文件中添加

复制代码代码如下:
<Files *>
Options -Indexes
</Files>

就可以禁止Apache显示目录索引。

2 thoughts on “禁止apache显示目录索引的常见方法(apache禁止列目录)

  • WillPost author

    # Further relax access to the default document root:

    #
    # Possible values for the Options directive are “None”, “All”,
    # or any combination of:
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that “MultiViews” must be named *explicitly* — “Options All”
    # doesn’t give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be “All”, “None”, or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted

发表回复