问题描述
我的托管服务器对我的网站进行了多次部署(开发,阶段,生产)。当且仅当它们设置的envirornment变量等于 dev时,如何才能在htaccess文件中添加HTTP Auth标头? (这意味着他们设置了一个名为SITE_ENVIRONMENT的变量,该变量可以根据您访问的站点进行开发,阶段或生产。
PS。我熟悉要求授权可以从htaccess中以普通方式访问,但在评估变量或根据结果编写块时我完全迷失了。
我不确定是否可以。
理论上,您可以使用:
RewriteCond%{ENV:SITE_ENVIRONMENT} ^ dev $
确定您所处的环境在,但我想不出如何编写RewriteRule来强制进行基本身份验证的方法...除非您重定向到另一个处理基本身份验证的页面,并将SITE_ENVIRONMENT变量重置为 dev-authenticated之类,否则。 / p>
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.
I'm not sure this is possible.
Theoreticaly, you can use:
RewriteCond %{ENV:SITE_ENVIRONMENT} ^dev$
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.
这篇关于根据apache env变量有条件地要求HTTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!