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
3
  • 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? Jan 15, 2012 at 22:09
  • Please clarify what do you expect from Apache? Jan 15, 2012 at 22:16
  • @ShaneMadden updated question.
    – Pentium10
    Jan 15, 2012 at 22:22

1 Answer 1

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
2
  • The rewrite rule, how can be used, to rewrite to some other directory, that is outside of the httdocs?
    – Pentium10
    Jan 16, 2012 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. Jan 16, 2012 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .