1

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] = 
$my_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 ? – Jai Sep 12 '17 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. – Waseem Abbas Sep 12 '17 at 13:20
  • Using subfolder for creating site doesnt mean that subfolder name will be visible in URL. – Jai Sep 13 '17 at 4:35
  • @Jai please explain ho i can achieve this using subfolder without having subfolder name in url. – Waseem Abbas Sep 13 '17 at 8:59
  • Ok. Posting answer. Please check and comment back if you face any issue in following that. – Jai Sep 13 '17 at 9:07
2

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:

Replace:

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

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

$bootstrap->run($app);

With:

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');
$bootstrap->run($app);
  • 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

| 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.