我是 .htaccess 的新手,我想知道如何使用 .htacces 来防止通过我的文件夹的 url 直接访问,例如localhost/mycart/images/或 localhost/mycart/css 应显示禁止消息。
目前我已将 index.php 放入我网站的每个文件夹中并回显消息,这是一个很好的方法。
当我访问我的网站,如 www.mycart/index.php/css 或 www.mycart/index.php/images 时,它显示没有图像和 css 的网站,为什么以及如何修复它?
最佳答案
我用过
# disable directory browsing
Options -Indexes
相反,要启用目录浏览,请使用以下指令:
# enable directory browsing
Options +Indexes
同样,此规则将阻止服务器列出目录内容:
# prevent folder listing
IndexIgnore *
最后,IndexIgnore 指令可用于阻止显示选定的文件类型:
# prevent display of select file types
IndexIgnore *.wmv *.mp4 *.avi *.etc
来自:Prevent Unauthorized Directory Browsing来自 Stupid HTACCESS Tricks .
它还包含许多其他有用的命令,可在 .htaccess
中使用,以增强安全性和性能。
关于php - 如何防止目录访问并在 php 中显示禁止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10773025/