I am facing issue while creating multi store in magento 2. I have added 2 store abc and xyz, each points to different domain.
I have added suggested code from different sites.
In index.php I added following code
switch($_SERVER['HTTP_HOST']) {
case 'dev.abc.com':
$mageRunCode='abc';
$mageRunType='store';
break;
case 'dev.xyz.com':
$mageRunCode='xyz';
$mageRunType='store';
break;
}
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
In .htaccess file I added
SetEnvIf Host dev.abc.com MAGE_RUN_CODE=abc
SetEnvIf Host dev.abc.com MAGE_RUN_TYPE=store
SetEnvIf Host dev.xyz.com MAGE_RUN_CODE=xyz
SetEnvIf Host dev.xyz.com MAGE_RUN_TYPE=store
Base url is also set for both store correctly in store configuration.
Now the problem is xyz store with dev.xyz.com is working fine however when i switch to abc store using store switcher its always redirect to xyz store dev.xyz.com
Please suggest me any solution. Is this store switcher issue or issue with multi domain, and how I will fix this issue.
Best Answer
I had the very same problem with MAGENTO 2.1.7 . After reading thousands (literally) of blogs, tutorials and websites I figured it out by sticking a few lines of code.
1 : Do not touch the .HTACCESS file. There's nothing to modify in there.
2 : Open INDEX.PHP and replace the following code
by this code :
There's 4 things to replace in the above code.