Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
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 '12 at 22:09
    
Please clarify what do you expect from Apache? –  Andrejs Cainikovs Jan 15 '12 at 22:16
    
@ShaneMadden updated question. –  Pentium10 Jan 15 '12 at 22:22

1 Answer 1

up vote 4 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
share|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 '12 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 '12 at 16:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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