Apache:将具有基本身份验证的文件夹重定向到安全服务器
过去,用户使用基本HTTP身份验证登录到私有文件夹。我们通过添加SSL证书对站点进行了升级,因此现在鼓励这些用户使用SSL来保护他们的密码 为了尝试从重定向到,我尝试了以下.htaccess文件:Apache:将具有基本身份验证的文件夹重定向到安全服务器,apache,mod-rewrite,https,basic-authentication,Apache,Mod Rewrite,Https,Basic Authentication,过去,用户使用基本HTTP身份验证登录到私有文件夹。我们通过添加SSL证书对站点进行了升级,因此现在鼓励这些用户使用SSL来保护他们的密码 为了尝试从重定向到,我尝试了以下.htaccess文件: RewriteCond %{HTTPS} =off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] AuthUserFile /usr/home/example/passwd AuthName "Private
RewriteCond %{HTTPS} =off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
AuthUserFile /usr/home/example/passwd
AuthName "Private Page"
AuthType Basic
问题在于,当用户导航到非SSL页面时,它会在重定向之前首先要求他们进行身份验证。这完全违背了目的。您可以尝试拆分您的重写规则和mod_auth指令: 在您放置的vHost中,这将在perdir.htaccess之前完成: 在/private/.htaccess中,您只有mod auth指令:
如果您使用的是Apache2.4,那么可以使用避免双重身份验证
#重定向到HTTPS
重新启动发动机
重写条件%{HTTPS}关闭
重写规则(.*)https://%{HTTP_HOST}%{REQUEST_URI}[R,L]
#仅在使用HTTPS时对用户进行身份验证
AuthType Basic
AuthName“特殊事物”
AuthUserFile/etc/blah.htpasswd
需要有效用户
RewriteCond %{HTTPS} =off
RewriteRule ^/?private https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
AuthUserFile /usr/home/example/passwd
AuthName "Private Page"
AuthType Basic
# Redirect to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Authenticate users only when using HTTPS
<If "%{HTTPS} == 'on'">
AuthType Basic
AuthName "Special things"
AuthUserFile /etc/blah.htpasswd
Require valid-user
</If>