Magento Multi-store device with different URLs / Domains (Magento 1 und Magento 2)

PictureHow to set up Magento 1.7 a, so that with different URLs or. Domains various shops / Stores bzw. Websites can reach?

Previously, this was the index.php reached. Now, this may directly over the .htaccess achieved.

PictureIn the first step you realize the Codes the various Websites. Subsequently, the. Htaccess and open at the bottom of the following Code added for each site:

SetEnvIf Host www.Domain1.de MAGE_RUN_CODE=base
SetEnvIf Host www.Domain1.de MAGE_RUN_TYPE=website
SetEnvIf Host ^Domain1.de MAGE_RUN_CODE=base
SetEnvIf Host ^Domain1.de MAGE_RUN_TYPE=website

The line 1 and 2 gives “when – then” an. The line 3 and 4 available in the event that the domain is entered without www.
Dignity for domain 2 der Website Code domain2 be, would then

SetEnvIf Host www.Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host www.Domain2.de MAGE_RUN_TYPE=website
SetEnvIf Host ^Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host ^Domain2.de MAGE_RUN_TYPE=website

If multiple URLs to point to one and the same website, this can also be added e.g..

SetEnvIf Host www.Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host www.Domain2.de MAGE_RUN_TYPE=website
SetEnvIf Host ^Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host ^Domain2.de MAGE_RUN_TYPE=website
SetEnvIf Host www.Domain3.de MAGE_RUN_CODE=domain2
SetEnvIf Host www.Domain3.de MAGE_RUN_TYPE=website
SetEnvIf Host ^Domain3.de MAGE_RUN_CODE=domain2
SetEnvIf Host ^Domain3.de MAGE_RUN_TYPE=website

Soll nur ein Store angesprochen werden, sähe der einzufügende Code so aus:

SetEnvIf Host www.Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host www.Domain2.de MAGE_RUN_TYPE=store
SetEnvIf Host ^Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host ^Domain2.de MAGE_RUN_TYPE=store

Im Falle eines Storeviews dann so

SetEnvIf Host www.Domain2.de MAGE_RUN_CODE=domain2
SetEnvIf Host ^Domain2.de MAGE_RUN_CODE=domain2

In bestimmten Fällen (bestimmte Serverkonfigurationen) kann es sein, dass dies alleine nicht ausreichend ist. Hier müsste man dann noch in der index.php eine kleine Änderung machen. Hier wird dann der Code

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Magus::run($mageRunCode, $mageRunType);

in

/* Store or website code */
$mageRunCode = isset($_SERVER['REDIRECT_MAGE_RUN_CODE']) ? $_SERVER['REDIRECT_MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['REDIRECT_MAGE_RUN_TYPE']) ? $_SERVER['REDIRECT_MAGE_RUN_TYPE'] : 'store';

Magus::run($mageRunCode, $mageRunType);

changed. Es wird dann ein Redirect beim Server angestoßen.

Weitere Beiträge mit Informationen zum Wechsel von Stores, Websites etc. gibt es in this und in this Eintrag.

UPDATE vom 06.09.2019

After a server update on Ubuntu 18.04 worked the diversions at each site no more and it became the standard- / Main site directed. It was no longer possible to achieve the desired stores the URLs.

To fix this, it was necessary to o.g. to make change in index.php reversed and again the original code

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Magus::run($mageRunCode, $mageRunType);

use.

Used in Magento versions 1.7-1.9 Ask, Comments, Proposals? Us directly or as a comment.

Magento 2.x this is done similarly.

Basically, it will be quite enough to make only the entries in the .htaccess (as described above). If this is not enough, can also be done with the index.php (recently in the folder / pub /) to be worked. For me it worked in most cases with the .htaccess adjustment.

Otherwise you wear into the index.php following lines (at exit })

$params = $_SERVER;
if( in_array($params["HTTP_HOST"], array("www.meinewunschdomain.de","meinewunschdomain.de")) ){
	$params[\MagentoStoreModelStoreManager::PARAM_RUN_CODE] = 'codedesstoreviews';
	$params[\MagentoStoreModelStoreManager::PARAM_RUN_TYPE] = 'store';
}else{
	$params[\MagentoStoreModelStoreManager::PARAM_RUN_CODE] = 'codedesstandardstoreviews';
	$params[\MagentoStoreModelStoreManager::PARAM_RUN_TYPE] = 'store';
}

“codedesstoreviews” here is the special StoreView, different from the default. you have as normal base URL e.g.. always a .com domain and only want to use for the German store view the .com domain, this would e.g.. Sun may look like above.

Update vom 05.05.2021

Was in Magento 2.2 still worked, didn't work anymore in the next version. The following code was then advised:


$params = $_SERVER;

switch($_SERVER['HTTP_HOST']) {

        case 'meinewunschdomain.de':
        #case 'www.meinewunschdomain.de':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'codedesstoreviews';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
        break;


        case 'meinewunschdomain2.de':
        #case 'www.meinewunschdomain2.de':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'codedesstandardstoreviews';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
        break;
    }

(by the way, it can simply be used instead of “store” the word “website” verwendet werden, if you want to use the code of the respective website or. wants to access the website.

Update vom 12.08.2021

Unfortunately, this code worked on Magento 2.4.2 again no more and so came - as with Magento 1- .htaccess comes into play again. An adjustment of the index.php is then no longer necessary or. superfluous.

SetEnvIf Host ^(.*)meinewunschdomain.de MAGE_RUN_CODE=codewebsite
SetEnvIf Host ^(.*)meinewunschdomain.de MAGE_RUN_TYPE=website

In this case I once used the code of a website, because I just needed this one. If instead of the above. Domain wants to use a subdomain, just replace the ^ with the appropriate subdomain.

Used in many Magento versions. Ask, Comments, Proposals? Us directly or as a comment.

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

One comment on “Magento Multi-store device with different URLs / Domains (Magento 1 und Magento 2)”

Leave a Reply

Your email address will not be published. Required fields are marked *