One method for controlling multiple stores involves adding SetEnvIf statements to .htaccess to set server variables MAGE_RUN_CODE and MAGE_RUN_TYPE.


However this method is sometimes prevented by server settings that block SetEnvIf from setting variables that don't begin with 'HTTP_'.

My answer below will show how to test for this.


First a reference: Answer by George Lerner at: https://stackoverflow.com/questions/17550223/set-an-environment-variable-in-htaccess-and-retrieve-it-in-php

To test, in [docroot]/.htaccess put a couple of lines like:

SetEnv HTTP_GRAHAMTEST httpgrahamtest
SetEnv GRAHAMTEST  grahamtest

Create [docroot]/php_server_env.php:

    <title>Environment variables Test</title>
    <?php echo '<p>Environment variables</p>'; ?>
    <?php print_r($_SERVER); ?>

This program lists the server environment variables that php receives from the server in the $_SERVER variable.

Browse to yoursite.com/php_server_env.php and view results to see which of the SetEnv'ed variables can be seen from php.

Needless to say, making certain that php can see your .htaccess variables goes along way to avoiding wasting a lot of time setting up multistores with the SetEnv method, which is otherwise straightforward.

Edit: Response from hosting company

This response from the support department of a popular hosting company, provides some technical details:

The mod_env module (used for all SetEnv and SenEnvif directives) is working properly, but suexec is cleaning all environmental variables before passing the script for execution.

When suexec is used to launch CGI scripts, the environment will be cleaned down to a set of safe variables before CGI scripts are launched. The list of safe variables is defined at the time of the Apache package compilation.

All our shared servers are using mod_hive which uses a more customized wrapper, instead of suexec. It passes variables that begin with "HTTP_", which then is visible in the $_SERVER array.

Unfortunately as your account is hosted on a shared hosting platform, we are not able to revert mod_env to its default state. What we can recommend you is to simply add HTTP_ prefix to all environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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