禁止“目录列表显示”(即防止访问者通过浏览器直接看到一个目录下的文件列表,出现类似 Index of / 的页面),常见做法如下,按服务器类型分类:
.htaccess在需要禁止目录列表的目录中新建或编辑 .htaccess 文件,加入:
Options -Indexes
✅ 禁止该目录及子目录列表显示
httpd.conf 或虚拟主机配置<Directory "/var/www/html">
Options -Indexes
</Directory>
autoindex在 nginx.conf 或站点配置中:
location / {
autoindex off;
}
如果是某个目录:
location /uploads/ {
autoindex off;
}
或在 web.config 中:
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
index.html如果你能告诉我:
我可以给你更精确的配置示例。