我试图用目录保护代码保护我的网站 . 该网站是PHP .
我的网站有https,就像https://www.example.com .
当我打开网站时,它要求输入两次用户名和密码 . 我认为它需要一次用于http,一次用于https .
谁能帮助我如何解决这个问题 .
以下是我 .htaccess file code
options -multiviews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>
AuthType Basic
AuthName "example.com"
AuthUserFile /www.example.com/web/content/.htpasswd
Require valid-user
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
在此先感谢您的帮助 .
1 回答
您将获得两次身份验证对话,因为Apache在
mod_rewrite
指令之前运行mod_auth
指令 . 此外,HTTP URL中的authentication
会话设置在HTTPS URL中无效,因此Apache也必须遵循HTTPS下的BASIC auth指令 .可以有一些
work-around
类型的解决方案可以跳过http URL的BASIC auth,并且仅针对HTTPS进行,但它不是直截了当的 .更新:这是一个解决方法,您可以使用它来避免两次显示BASIC身份验证对话框 .
由于cookie仅为
http://domain.com
设置,因此env变量也只设置一次 BASIC auth dialog is also shown only once .