I have several Aliasses configured in apache configuration. I would like to set an environmental variables for each of them. How?

I have this

/alias1 /mapped/to/a/path
/alias2 /mapped/to/a/path
/alias3 /mapped/to/a/path
/alias4 /mapped/to/a/path
/alias5 /mapped/to/a/path

what I want is to forward an environmental variable, for each alias

something like

/alias1 /mapped/to/a/path AND SetEnv VAR=a
/alias2 /mapped/to/a/path AND SetEnv VAR=b
/alias3 /mapped/to/a/path AND SetEnv VAR=c
/alias4 /mapped/to/a/path AND SetEnv VAR=d
/alias5 /mapped/to/a/path AND SetEnv VAR=e
link|improve this question

67% accept rate
Can you clarify what you're trying to accomplish? To have an env set based on which alias a request is getting sent to, maybe? – Shane Madden Jan 15 at 22:09
Please clarify what do you expect from Apache? – Andrejs Cainikovs Jan 15 at 22:16
@ShaneMadden updated question. – Pentium10 Jan 15 at 22:22
feedback

1 Answer

up vote 3 down vote accepted

Well, this should do it:

SetEnvIf Request_URI ^/alias1 VAR=a
SetEnvIf Request_URI ^/alias2 VAR=b
SetEnvIf Request_URI ^/alias3 VAR=c
SetEnvIf Request_URI ^/alias4 VAR=d
SetEnvIf Request_URI ^/alias5 VAR=e

If you need more flexibility on matching or conditions for some reason, you could also use mod_rewrite:

RewriteEngine On
RewriteRule ^/alias1 - [E=VAR:a]
RewriteRule ^/alias2 - [E=VAR:b]
RewriteRule ^/alias3 - [E=VAR:c]
RewriteRule ^/alias4 - [E=VAR:d]
RewriteRule ^/alias5 - [E=VAR:e]

For domain like alias the answer is:

SetEnvIf Host www\.domain\.de MAGE_RUN_CODE=default
SetEnvIf Host www\.domain\.de MAGE_RUN_TYPE=website
link|improve this answer
The rewrite rule, how can be used, to rewrite to some other directory, that is outside of the httdocs? – Pentium10 Jan 16 at 8:12
@Pentium10 These rewrite rules are just setting environment variables, not changing directories. That's what your Alias directives are for - though mod_rewrite can certainly do that job as well if you need it to. – Shane Madden Jan 16 at 16:09
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.