Magento2 Multistore – Link Store View to Different URL

magento2multistore

I created a new store view with code 'fr'. I have changed the base Url of that store view to 'http://127.0.0.1/magento/fr/'. I created the new folder with name 'fr' and copied .htaccess file and index.php inside it. Now I changed index.php like below:

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'fr';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);

Now when I am hitting 'http://127.0.0.1/magento/fr/' it's showing the default store view instead of store view with code 'fr'. Can anyone tell what's wrong with the procedure ? Thanks!

Best Answer

Follow this step to add store code in url :

  • In the Admin, click Stores > Settings > Configuration > General > Web.
  • From the Store View list at the top of the page, click Default Config as the following figure shows.
  • In the right pane, expand Url Options.
  • Clear the Use system value checkbox next to Add Store Code to Urls.
  • From the Add Store Code to Urls list, click Yes as the following figure shows.
  • Click Save Config.
  • Flush the Magento cache. (System > Cache Management).
Related Topic