English 中文(简体)
在.htaccess 中有条件设置 Env 吗?
原标题:Conditional SetEnv in .htaccess?

能否根据主机名在.ht access 文件中设置 SetEnv 变量?

例如,我需要我的 .htaccess 文件具有以下值:

SetEnv PYRO_ENV production

在生产盒上 还有...

SetEnv PYRO_ENV stage

在设置框上。 .htaccess 文件受版本控制, 所以我才寻找有条件的解决方案 。

最佳回答

对于有条件设置而言,"http://http://httpd.apache.org/docs/text/mod/mod_setenvif.html#setenvif' rel=“noreferr'>SetEnvif :

SetEnvIf Host ^stage.example.com$ PYRO_ENV=stage
SetEnvIf Host ^(www.)?example.com$ PYRO_ENV=production
问题回答

您可以, 使用 mod_ rewrite :

RewriteEngine on

RewriteCond %{HTTP_HOST} ^stage.domain.com$
RewriteRule (.*) $1 [E=PYRO_ENV:stage]

RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule (.*) $1 [E=PYRO_ENV:production]




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签