Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In our httpd.conf virtual host block we have

SetEnv MAGE_RUN_CODE "v2_us_es"

Is it possible to use that variable in a .htaccess file

Something like

RewriteRule ^sitemap\.xml$ /media/sitemaps/%{MAGE_RUN_CODE}/sitemap.xml [L]

Is this possible?

Thank you!

Jeff

Edit: I viewed the following links, but none of them do what I am trying to do

http://stackoverflow.com/questions/10727720/conditional-setenv-in-htaccess http://stackoverflow.com/questions/2008123/how-to-use-getenv-in-php-and-setenv-in-a-htaccess-with-a-compiled-php-cgi-on http://stackoverflow.com/questions/3638637/how-to-use-the-setenv-variable-in-apache

share|improve this question
up vote 2 down vote accepted

The syntax to use environment variables in mod_rewrite is %{ENV:VARNAME}:

RewriteRule ^sitemap\.xml$ media/sitemaps/%{ENV:MAGE_RUN_CODE}/sitemap.xml [L]
share|improve this answer

SetEnv variables just return empty strings in a RewriteRule. I think this is because they haven't been set when the RewriteRule is executed. But SetEnvIf will work, so you could try:

SetEnvIf Request_URI ^.*$ MAGE_RUN_CODE=v2_us_es

and then use it with:

RewriteRule ^sitemap\.xml$ /media/sitemaps/%{ENV:MAGE_RUN_CODE}/sitemap.xml [L]

The Request_URI ^.*$ bit in the SetEnvIf just checks that the requested page is something or nothing, so always sets the variable.

It would probably be better configured as a 'RewriteMap' in the Apache config file.

share|improve this answer

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.