密码保护虚拟目录? - .htpasswd/.htaccess

Ker*_*nes 5 apache .htaccess basic-authentication virtual-directory .htpasswd

是否可以使用密码保护虚拟目录(例如wordpress类别):

/c/sofas/
Run Code Online (Sandbox Code Playgroud)

它看起来像<Location /c/sofas/>在httpd_config中工作,但不是.htaccess

可能吗?可能在某处有mod_rewrite?

anu*_*ava 12

不幸的是,<Location>指令是不允许的.htaccess.

但是有一个替代的整洁解决方案使用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
Run Code Online (Sandbox Code Playgroud)