How to switch among multiple websites in Magento 2

If you have multiple website and you need to test them on your development environment. How do you do that?

In case multiple store, Magento 2 permit you switch among stores through nav bar on header or footer. But nothing for multiple websites

To do that, you can follow the below steps:

Step 1: Build a new file index2.php in root folder

Step 2: Include this code

Step 3: Modify this code with your case

Step 4: Enter you Magento site

  1. Build a new file index2.php in root folder
  2. Include this code
<?php

try {

require __DIR__ . '/app/bootstrap.php';

} catch (\Exception $e) {

echo <<<HTML

<div style="font:12px/1.35em arial, helvetica, sans-serif;">

<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">

     <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">

     Autoload error</h3>

</div>

<p>{$e->getMessage()}</p>

</div>

HTML;

exit(1);

}

$params = $_SERVER;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = '<code>';

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = '{store|website}';

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

/** @var \Magento\Framework\App\Http $app */

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

$bootstrap->run($app);
  1. Modify this code with your case

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘<code>’;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘{store|website}’;

  • Example:

You have website with code = website_a

  • Let change code:

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘website_a’;

$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘website’;

  1. Enter you Magento site
  • Enter your Magento site with URL: http://magento2.com/index2.php
  • Reference: http://devdocs.magento.com/guides/v2.1/config-guide/multi-site/ms_over.html
  • http://devdocs.magento.com/guides/v2.1/config-guide/multi-site/ms_apache.html

Last Update: March 5, 2018  

March 5, 2018   248   Nandini Ramachandran    Operations    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

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

Facebook
Twitter
INSTAGRAM
LinkedIn