在站点根目录下使用.htpasswd .htaccess导致redirect循环

我想临时密码保护一个网站。

我在站点根目录中有一个.htaccess文件,其中包含:

AuthType Basic AuthName "Example Site Name" AuthUserFile /home/my_username/.htpasswd Require valid-user 

当我访问example.com时 ,会抛出一个login窗口,但是当我进行身份validation时,我得到一个310错误:

此网页有redirect循环

http://example.com/上的网页导致了太多的redirect。 清除本网站的Cookie或允许第三方Cookie可能会解决此问题。 如果没有,这可能是一个服务器configuration问题,而不是您的计算机的问题。

错误310(net :: ERR_TOO_MANY_REDIRECTS):有太多的redirect。

现在,每次击中example.com都会给我这个错误,而不要求我进行身份validation。

为什么发生这种情况?

在你的httpdconfiguration中,你可能没有定义任何错误文件,所以它试图返回到基本页面,抛出一个错误,漂洗,重复。

尝试添加:

ErrorDocument 401 /[path_to_file]/error.html
ErrorDocument 403 /[path_to_file]/error.html

到您的.htaccess文件。 当然,确保那些简单的error.html文件也存在。