4

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
Pentium10
  • 444
  • 1
  • 9
  • 23

1 Answers1

6

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
Pentium10
  • 444
  • 1
  • 9
  • 23
Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • The rewrite rule, how can be used, to rewrite to some other directory, that is outside of the httdocs? – Pentium10 Jan 16 '12 at 08: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 '12 at 16:09