【问题标题】:Password protect nested directories with .htaccess使用 .htaccess 密码保护嵌套目录
【发布时间】:2015-05-09 00:35:13
【问题描述】:

我有多个类似这样的目录:

root
  - directory 1
  - directory 2
  - directory 3
     - sub directory 1
     - sub directory 2
     - sub directory 3

Root 现在受 .htaccess 保护,

我想做的是用不同的用户名/密码保护子目录 1、2 和 3

这可以吗?如果有怎么办?

现在我位于目录 3 中的 .htaccess 文件如下所示:

AuthUserFile path/path/path/sub directory 1/ .htpasswd
AuthUserFile path/path/path/sub directory 2/ .htpasswd
AuthUserFile path/path/path/sub directory 3/ .htpasswd

AuthName "Please Log In"
AuthType Basic
require valid-user

但是它不起作用...我得到内部错误服务器

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    您需要在每个指向特定 htpassword 文件的子目录中都有一个单独的 htaccess 文件。您不能像在 htaccess 中那样分离哪些子目录使用哪个 htpasswd 文件。

    另外,页面中不要留空格,apache 会认为你指的是一个指令的多个参数。

    所以在每个子目录的 htaccess 文件中,尝试类似:

    AuthUserFile .htpasswd
    AuthName "Please Log In"
    AuthType Basic
    require valid-user
    

    但请注意,将密码文件留在 webroot 中以供人们下载通常是一个非常糟糕的主意

    【讨论】:

    • 你建议我在哪里存储 passwd 文件
    • @TimLee 把它放在你的 webroot 之外。您可以在 webroot 之外使用 AuthUserFile 指定路径。
    猜你喜欢
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多