我有一个网站http://www.example.com
也是虚拟目录或网址http://www.example.com/admin/
请注意,没有名为/admin
的实际目录
如何使用http://www.example.com/admin/
密码保护此.htaccess
网址?
我尝试过这些方法:
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^(.*)$ /adminpanel/%1 [PT]
<LocationMatch "/adminpanel/">
AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /home/example/public_html/.htpasswd
Require valid-user
</LocationMatch>
锁定整个网站
此方法也不成功:
SetEnvIfNoCase Request_URI "^/adminpanel" SECURED
# invoke basic auth is SECURED is set
#Deny from env=SECURED
AuthType Basic
#Require valid-user
AuthName "My Protected Area"
AuthUserFile /home/example/public_html/.htpasswd
Require valid-user
#Satisfy any
Order allow,deny
Deny from env=SECURED
Allow from all
Satisfy any
答案 0 :(得分:0)
您不需要重写规则 - 您在该实例中将所有内容重定向到/adminpanel
。您只需添加以下内容:
<Location "/adminpanel">
AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /home/example/public_html/.htpasswd
Require valid-user
</Location>