【问题标题】:.htaccess : How to prohibit access to a directory?.htaccess : 如何禁止访问一个目录?
【发布时间】:2016-11-27 10:16:01
【问题描述】:

这是我当前 PHP 项目的文件夹结构:

root
   |_classes
   |_ctrl
   |_pages
   |_webroot
     |_index.php
   |_config.php

这是我的问题:

/webroot/index.php 是网络根目录。 index.php 文件包含用户请求的每个页面。这些页面存储在/pages。所以我需要我的网站能够访问文件夹结构中位于较高位置的文件夹。

但我也不希望用户有权访问所有其他文件和文件夹(config.phpclasses/、...)。

也就是说,我的网站看起来像这样:www.mysite.com/webroot/index.php。我不希望用户去www.mysite.com/config.php,或www.mysite.com/classes/...等。

哦,是的,当然,我不希望用户的浏览器在 url 中显示 webroot 文件夹,那么是否可以重写 url 以使其看起来更好?

我该怎么做?

提前致谢。

【问题讨论】:

    标签: php .htaccess structure directory


    【解决方案1】:

    好的,所以我找到了解决方案。我已将这些指令添加到我的 .conf 文件中:ServerRootDocumentRoot

    • ServerRoot 是服务器的根。用户不一定有权访问根目录。
    • DocumentRoot 是用户可以访问的路径。

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-11-09
      • 2021-05-17
      • 1970-01-01
      • 2013-08-07
      相关资源
      最近更新 更多