【问题标题】:Protect directory with htaccess/htpasswd error from root htaccess file?使用根 htaccess 文件中的 htaccess/htpasswd 错误保护目录?
【发布时间】:2019-04-25 03:17:23
【问题描述】:

我的根目录中有一个 htaccess 文件,用于添加规则,例如在网站上强制 www 等。

我想保护我网站上的目录,例如 example.com/private/ 和 example.com/private/p/

这里是我的 htaccess 文件所在的位置:

/public_html/.htaccess (htaccess file to force www. on my site)
/public_html/private/.htaccess (protect directory code)
/public_html/private/.htpasswd (usernames and passwords for directory)

当我尝试单击指向 /private/ URL 的链接时,我不断收到 401 Unauthorized,有时甚至没有得到密码提示。我已尝试清除缓存,但仍然无法正常工作。

这是我的 /private/.htaccess 代码(保护目录代码)(我知道我的 AuthUserFile 路径是对的):

AuthType Basic
AuthName "Members Only"
AuthUserFile /public_html/private/.htpasswd
<limit GET PUT POST>
require valid-user
</limit>

当我删除 /public_html/.htaccess 文件时,登录工作正常。任何人都知道为什么以及如何解决这个问题,以便我可以同时使用这两个 .htaccess 文件?

【问题讨论】:

    标签: apache .htaccess password-protection .htpasswd


    【解决方案1】:

    尝试将 .htpasswd 的路径(在“AuthUserFile /public_html/private/.htpasswd”行中)更改为文件的完整路径。示例 /home/username/www/public_html/private/.htpasswd

    【讨论】:

    • 是的,我确定 AuthUserFile 是正确的。它一直是AuthUserFile /storage/ssd4/782/3883334/public_html/private/.htpasswd,它工作得很好。我没有收到提示似乎是 ssl 的问题。当我通过 cloudflare 关闭 https 时,它似乎工作正常,并且我像往常一样得到弹出窗口。知道为什么它不适用于 https 吗?
    猜你喜欢
    • 1970-01-01
    • 2012-07-02
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    相关资源
    最近更新 更多