基本受保护的文件夹重定向到https 401页面并导致问题

时间:2016-12-04 18:09:27

标签: apache .htaccess ssl

所以我将所有请求重定向到我的网站到www和https版本MINUS一个文件夹。那个文件夹恰好是密码保护的。我需要使用常规http访问该文件夹(将其从重定向中排除的原因),但是当我这样做时会出现401错误。如果我使用https访问它,那么浏览器会正常提示我输入用户/通行证。为什么会发生这种情况?我该如何解决?

/ public_html / htaccess

# BEGIN non-www to www with https: (with exclusions)
RewriteCond %{REQUEST_URI} !^/protected/
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

/ public_html / protected / htaccess

AuthType Basic
AuthName "Protected Access"
require valid-user
AuthUserFile "/home/example/.htpasswds/public_html/protected/passwd"

问题

由于我从www和https重定向中排除了此文件夹,因此我应该'能够通过http或https访问/ protected /中的任何文件。问题是http://example.com/protected/somefile.htm重定向到https 401错误页面,甚至没有提示我输入用户/通行证。

另一方面https://example.com/protected/somefile.htm工作正常 - 它会提示我输入用户/通行证并且效果很好。

我不明白为什么会发生这种情况,而且我必须能够使用http和非ssl访问该文件夹中的文件。

我应该补充一点,htaccess规则是正确的'好像我注释掉了用户/传递保护的行,它可以正常工作,并且可以提供http / https。只有当文件夹被发现时才会出现此问题。

0 个答案:

没有答案