Conditional SetEnv in .htaccess?

2020-05-14 10:35发布

Is it possible to set a SetEnv variable in an .htaccess file differently depending on hostname?

For example, I need my .htaccess file to have the following value:

SetEnv PYRO_ENV production

On production boxes, and...

SetEnv PYRO_ENV stage

On staging boxes. The .htaccess file is version controlled, which is the reason I'm looking for a conditional solution.

2条回答
ゆ 、 Hurt°
2楼-- · 2020-05-14 11:25

For conditional settings there is SetEnvIf:

SetEnvIf Host ^stage\.example\.com$ PYRO_ENV=stage
SetEnvIf Host ^(www\.)?example\.com$ PYRO_ENV=production
查看更多
Ridiculous、
3楼-- · 2020-05-14 11:34

You can, with 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]
查看更多
登录 后发表回答