【问题标题】:prevent root directory access publicly for my domain阻止公开访问我的域的根目录
【发布时间】:2018-05-25 20:40:05
【问题描述】:

其实我有一个网站 www.domain.com

当我试图检查元素并尝试访问 www.domain.com/css/ 然后它显示了目录中的所有文件

结构

  • /css/
  • /图片/
  • /包括/
  • /js/
  • index.html
  • contact.html
  • sitemap.xml
  • style.css
  • robot.txt
  • .htaccess

我想保护 css,images,include,js 文件夹意味着如果有人尝试访问 www.domain.com/images/,那么他应该被重定向到 www.domain。 com/index.html rest index.html,contact.html,sitemap,robot.txt 应该可以公开访问,www.domain.com/images/abcd.jpg 可以公开访问但 www.domain.com/images/ 不应公开访问。

谁能告诉我该怎么做?

【问题讨论】:

  • 在所有文件夹中放置一个空白的index.html 文件。如果您想通过 htaccess 执行此操作,请输入Options -Indexes
  • 使用 htaccess 重定向到 index.html
  • 最好用403禁止处理,而不是

标签: javascript php html css .htaccess


【解决方案1】:

您可以在服务器配置或 .htaccess 中使用此选项禁用目录列表:

Options -Indexes

详情请看:https://wiki.apache.org/httpd/DirectoryListings

要将用户重定向到您的主页,请使用重写规则或在您的 HTTP 403/404 错误页面中添加重定向。

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 2012-07-30
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2012-07-27
    • 1970-01-01
    相关资源
    最近更新 更多