根据 apache 环境变量,有条件地要求 HTTP 身份验证
我的托管有我的站点的多个部署(开发、阶段、生产)。当且仅当它们设置的环境变量等于“dev”时,如何在我的 htaccess 文件中添加 HTTP Auth 标头? (这意味着他们设置了一个名为 SITE_ENVIRONMENT 的变量,该变量可以是 dev、stage 或 prod,具体取决于您访问的站点。PS
。我熟悉以普通方式要求 htaccess 授权,但当它出现时我完全迷失了评估变量或根据结果编写块。
My hosting has multiple deployments of my site (dev, stage, production). How can I add HTTP Auth headers in my htaccess file if and only if the enviornment variable that they set is equal to 'dev'? (meaning they set a variable called SITE_ENVIRONMENT that can be dev, stage, or prod depending on which site you're accessing.
PS. I'm familiar with requiring authorization from htaccess in vanilla ways, but I'm totally lost when it comes to evaluating variables or writing a block based on the outcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 SetEnvIf 来模式匹配域并确定要使用的环境。
男子:http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html
You can use SetEnvIf to pattern match the domain and determine which environment to use.
Man: http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html
我不确定这是否可能。
理论上,您可以使用:
确定您所处的环境,但我无法想到如何编写 RewriteRule 来强制进行基本身份验证...除非您重定向到处理基本身份验证并重置 SITE_ENVIRONMENT 的另一个页面变量为“开发人员验证”或其他内容。
I'm not sure this is possible.
Theoreticaly, you can use:
to determine which environment you're in, but I can't think of how to write the RewriteRule to force a basic auth... unless you redirected to another page which handles the basic auth and resets the SITE_ENVIRONMENT variable to "dev-authenticated" or something.