Setup Multi Store With Multi Domain in Magento 2

In this post we’ll guide you how to Setup Multi Store With Multi Domain in Magento 2. One of Magento’s greatest strengths is its capabilities for scaling to support multi-site, multi-store and multi-language retailing all from the single admin. One instance of the Magento software can enable you to start multiple websites or store views that use different Default languages, Domain names, Categories.

This feature allows you create websites, stores as many as you need only in the single configuration. All stores share the same domain, be set up as subdomains of the same domain, or have entirely different domain, especial, possibly share the same backend for the easier adminstration. Magento is one of the best solutions for multi-store functionality.

Follow the guides in detail to apply Multi Store With Multi Domain in Magento 2. Addtionaly, you can add multiple websites for each store you want to configure. Please Click Here and refer Magento 2 official Document to know how to Set up multiple websites, stores, and store views in the single Magento 2 Admin.

After set up multiple websites, stores, and store views if you want to use multi domain for multi stores you just need to modify index.php file which is locate on your Magento Root. Open index.php file and replace following code with that and change domain and website, store or storeview code as I explain you below of the code.

saveCopyzoom_out_map
<?php /** * Application entry point * * Example - run a particular store or website: * -------------------------------------------- * require __DIR__ . '/app/bootstrap.php'; * $params = $_SERVER; * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2'; * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = '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); * -------------------------------------------- * * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ 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; $domain2store = array( 'domain1.com'=>'default', // Replace your Website, Store or Storeview code with this. 'domain2.com'=>'de', // Replace your Website, Store or Storeview code with this. 'domain3.com'=>'es', // Replace your Website, Store or Storeview code with this. 'domain4.com'=>'fr', // Replace your Website, Store or Storeview code with this. ); if(isset($domain2store[$_SERVER['HTTP_HOST']])) $storecode = $domain2store[$_SERVER['HTTP_HOST']]; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = isset($storecode) ? $storecode : ''; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);

Let me explain you some code. you can add more domain by "," saprate. In following code we have add different domain and assign to different Storeview. So what you need to change in this code is to replace Replace your Website, Store or Storeview code with that.

saveCopyzoom_out_map
$domain2store = array( 'domain1.com'=>'default', // Replace your Website, Store or Storeview code with this. 'domain2.com'=>'de', // Replace your Website, Store or Storeview code with this. 'domain3.com'=>'es', // Replace your Website, Store or Storeview code with this. 'domain4.com'=>'fr', // Replace your Website, Store or Storeview code with this. );

After made this changes you just need to save the index.php file and upload it to your server. That’a it. Now run the domain1.com and you’ll see specific Website, Store or Storeview you assign to that store.

We hope this Magento post helped you to Setup Multi Store With Multi Domain in Magento 2. Bookmark it for your future reference. Do comment below if you have any other questions or doubts.

P.S. Do share this post with your team.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off