我通过一个.htaccess文件为我的webspaceconfiguration身份validation(我无法控制httpd.conf文件)。 对于一个安全的实现,我有一个HTTP自动redirect到HTTPS通过
RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=307,L]
对于身份validation,我使用以下几行
AuthType Basic AuthName name AuthUserFile ..path-to-htpasswd.. require valid-user
如果我通过http访问资源,我必须input用户名和密码两次(第一次获得307redirect,第二次获得实际文档)。 是否有一种方法仅适用于HTTPS-Requestauthentication? 所以一个HTTP请求直接获得redirect,这样我就只需要对自己进行一次authentication。
问候并感谢您的回答
您应该能够利用以下事实,即重写文件之前先进行处理:
RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=307,L] <FilesMatch "."> AuthType Basic AuthName name AuthUserFile ..path-to-htpasswd.. require valid-user </FilesMatch>
. 是一个正则expression式通配符,所以authentication仍然适用于所有有效的请求,但只有在重写发生后