I have two stores in magento 2, one store has store code "abc" points to domain "www.abc.com" and other store has store code "xyz" points to domain "www.xyz.com".

When I set Add store code to url option to Yes. My both store working fine. Both store cart and account sharing worked. but I don't want to use store code in url for SEO purpose, and when I set Add store code to url option to No. Cart and account sharing stop to work.

enter image description here

When I logout from one store, I still login in other store. I checked SID in both store. Both store has different SID.

I added following code in index.php

if($_SERVER['SERVER_NAME'] == 'www.abc.com') {
$my_param_run_code = 'abc';

else {
$my_param_run_code = 'xyz';

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

also I added following in top of .htaccess file

SetEnvIf Host abc.com MAGE_RUN_CODE=abc
SetEnvIf Host abc.com MAGE_RUN_TYPE=store
SetEnvIf Host ^abc.com MAGE_RUN_CODE=abc
SetEnvIf Host ^abc.com MAGE_RUN_TYPE=store

SetEnvIf Host xyz.com MAGE_RUN_CODE=xyz
SetEnvIf Host xyz.com MAGE_RUN_TYPE=store
SetEnvIf Host ^xyz.com MAGE_RUN_CODE=xyz
SetEnvIf Host ^xyz.com MAGE_RUN_TYPE=store

Where I am wrong in setting of multistore, I want cart and account sharing on both store without using Add store code to url option and also without using store switcher. I want my both store use same SID, when SID update on one store, it automatically update on other store as well.

  • index file should be updated only of child store. This is what you did or this file is of main installation index.php ?
    – Jarnail S
    Commented Sep 12, 2017 at 12:51
  • @Jai I have only one index.php file and that is of main installation. I did not creating sub folder. I don't want to use sub folder name in url for my stores. Commented Sep 12, 2017 at 13:20
  • Using subfolder for creating site doesnt mean that subfolder name will be visible in URL.
    – Jarnail S
    Commented Sep 13, 2017 at 4:35
  • @Jai please explain ho i can achieve this using subfolder without having subfolder name in url. Commented Sep 13, 2017 at 8:59
  • Ok. Posting answer. Please check and comment back if you face any issue in following that.
    – Jarnail S
    Commented Sep 13, 2017 at 9:07

1 Answer 1


Please follow these steps for creating multi-websites:

  • Verify your desired domain name points to the server.
  • Create a secondary domain for your new store.
  • Using either FTP or SSH, copy the .htaccess and index.php files from your Magento installation to the document root of your new domain.
  • Open the index.php file that you just copied and edit the last lines of the file as follows:


$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

/** @var \Magento\Framework\App\Http $app */
$app = bootstrap->createApplication('Magento\Framework\App\Http');



require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstore'; //this is website code not store code
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';  // leave it as it.
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
  • Using SSH, create the following symbolic links in the document root of your new domain, and replace the path below with the full path to the document root of your Magento Installation:

ln -s /home/example/example.com/html/app/ app

ln -s /home/example/example.com/html/lib/ lib

ln -s /home/example/example.com/html/pub/ pub

ln -s /home/example/example.com/html/var/ var

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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