使用根htaccess文件中的htaccess / htpasswd错误保护目录?

时间:2019-04-25 03:17:23

标签: apache .htaccess password-protection .htpasswd

我在根目录中有一个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文件吗?

1 个答案:

答案 0 :(得分:0)

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