1

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

http://devdocs.magento.com/guides/v2.1/config-guide/multi-site/ms_apache.html

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.

1

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:

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

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.

| improve this answer | |

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.