我如何能有一个有条件的.htaccess块? [英] How Can I Have A Conditional .htaccess Block?
问题描述
这是你以前可能会遇到一个Apache的问题。我想有一个源码包,我可以部署到我的工作站,我的临时服务器,我的生产服务器,但它加载基于什么的网址是不同的.htaccess设置。
This is an Apache question you've probably come across before. I want to have one source package that I can deploy to my workstation, my staging server, and my production server, but for it to load different .htaccess settings based on what the URL was.
请注意,我用用IfModule调用一个杂牌组装电脑,但不会有我们新的生产服务工作,因为它的股票都是一样的模块,我临时服务器。
Note that I was using a kludge with an IfModule call, but that won't work with our new production server because it shares all the same modules as my staging server.
请注意,我需要捆绑SETENV这些重写。目前,如果你使用的RewriteCond,它只关系到以下重写规则,但骨子里不是SETENV。
Note I need to bundle SetEnv with these rewrites. Currently if you use RewriteCond, it only ties to the following RewriteRule, but not the SetEnv underneath.
推荐答案
而不是使用SETENV的,使用重写规则本身的环境变量设置功能:
Instead of using SetEnv, use the environment variable setting capabilities of RewriteRule itself:
RewriteCond %{HTTP_HOST} =foo.com
RewriteRule ^ - [E=VARNAME:foo]
RewriteCond %{HTTP_HOST} =bar.com
RewriteRule ^ - [E=VARNAME:bar]
虽然我preFER传递标志的httpd进程的启动和寻找他们使用IfDefine块做这样的事情。
Although I prefer doing this sort of thing by passing flags to the httpd process at startup and looking for them using IfDefine blocks.
<IfDefine FOO>
SetEnv VARNAME foo
</IfDefine>
<IfDefine BAR>
SetEnv VARNAME bar
</IfDefine>
这篇关于我如何能有一个有条件的.htaccess块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!