当前位置: 移动技术网 > 网络运营>服务器>Linux > 禁止apache显示目录索引的常见方法(apache禁止列目录)

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

2019年05月02日  | 移动技术网网络运营  | 我要评论

禁止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 的作用就是当该目录下没有 文件时,就显示目录结构,去掉 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 mail@jb51.com
    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显示目录索引。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网