禁止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显示目录索引。
您可能感兴趣的文章:
- Apache 虚拟目录和默认首页的设置
- Apache Rewrite实现URL的301跳转和域名跳转
- windows中apache 301页面跳转实现方法
- 让apache显示目录列表的配置方法
- apache设置自动将http跳转到https的方法
- Apache mod_rewrite实现HTTP和HTTPS重定向跳转
- Apache中使非伪静态url跳转到伪静态url的方法
- Apache中解决动态地址跳转死循环的方法
- Apache的Rewrite设置多域名301跳转到主域名的方法
- Apache无法自动跳转却显示目录的解决方法
本文由 华域联盟 原创撰写:华域联盟 » 禁止apache显示目录索引的常见方法(apache禁止列目录)
转载请保留出处和原文链接:https://www.cnhackhy.com/46567.htm