Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache:将具有基本身份验证的文件夹重定向到安全服务器_Apache_Mod Rewrite_Https_Basic Authentication - Fatal编程技术网

Apache:将具有基本身份验证的文件夹重定向到安全服务器

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

过去,用户使用基本HTTP身份验证登录到私有文件夹。我们通过添加SSL证书对站点进行了升级,因此现在鼓励这些用户使用SSL来保护他们的密码

为了尝试从重定向到,我尝试了以下.htaccess文件:

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>