Is it possible to password protect a virtual directory (such as a wordpress category):
是否可以使用密码保护虚拟目录(例如wordpress类别):
/c/sofas/
It looks like <Location /c/sofas/>
would work in httpd_config, but not .htaccess
看起来
Is it possible? Possibly with a mod_rewrite somewhere?
可能吗?可能在某处有一个mod_rewrite?
1 个解决方案
#1
11
Unfortunately <Location>
directive isn't allowed in .htaccess
.
不幸的是,.htaccess中不允许使用
But there is an alternate neat solution using mod_setenvif
.
但是使用mod_setenvif还有另一种简洁的解决方案。
# set env variable SECURED if current URI is /c/sofas/
SetEnvIfNoCase Request_URI "^/c/sofas/" SECURED
# invoke basic auth is SECURED is set
AuthType Basic
AuthName "My Protected Area"
AuthUserFile /full/path/to/passwords
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=SECURED
#1
11
Unfortunately <Location>
directive isn't allowed in .htaccess
.
不幸的是,.htaccess中不允许使用
But there is an alternate neat solution using mod_setenvif
.
但是使用mod_setenvif还有另一种简洁的解决方案。
# set env variable SECURED if current URI is /c/sofas/
SetEnvIfNoCase Request_URI "^/c/sofas/" SECURED
# invoke basic auth is SECURED is set
AuthType Basic
AuthName "My Protected Area"
AuthUserFile /full/path/to/passwords
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=SECURED