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

标签 apache .htaccess virtual-directory basic-authentication .htpasswd

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

/c/sofas/

它看起来像 <Location /c/sofas/>可以在 httpd_config 中工作,但不能在 .htaccess 中使用

是否可以?可能在某处使用 mod_rewrite 吗?

最佳答案

不幸的是<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

关于apache - 密码保护虚拟目录? - .htpasswd/.htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19328665/

相关文章:

apache - 从源代码 Redhat 6 安装 Apache2 时遇到问题

php - 有人知道任何好的后端用户在线文件管理器吗?

apache - 连续多个 RewriteCond 将子域重定向到新子域

php - 在apache php上实现http2推送方法

windows - Tomcat 中的虚拟目录不起作用

asp.net - 访问远程服务器 IIS7 上的虚拟目录时出现运行时错误

python - Django + apache & mod_wsgi : having to restart apache after changes

macos - 在 mac os Sierra 上设置 apache Web 服务器(macbook pro 13 2014)

php - 强制 Heroku PHP 应用程序对 www 和非 www 版本都使用 https

asp.net - 如何在 ASP.NET 项目中正确引用 JavaScript 文件?