Table of Content

https://www.youtube.com/watch?v=1HrOfr8e96A

In my localhost, I have two domains named

  1. website.vn
  2. website.us

Both these websites pointing to same the path /var/www/html/magento/2.2.x/2.2.5

Let’s do this practice, you need to follow steps by step:

Step 1: Add a new Root Category

  • Log into the backend and navigate to the Catalog → Catalog → Categories → Add Root Category
  • Enter the Category Name
  • Press the button Save.

Step 2: Create a new website

  • Go to the Stores → Settings → All Stores → Create Website
  • Enter the Web Site Information
  • Press the button Save Web Site.

Step 3: Create a new Store for the second website

  • Go to the Stores → Settings → All Stores → Create Store
  • Enter the store information
  • Press the button Save Store.

Step 4: Create Default Store View for the second website

  • Go to the Stores → Settings → All Stores → Create Store View
  • Enter the Store view information
  • Press the button Save Store View.

Step 5: Setup the Base URL for the new website

  • Go to the Stores → Settings → Configuration → General → Web
  • On the top-left, in the box to view and manage the Store view, select the new website you just created. Go to the Base URLs and Base URLs (Secure) section.
  • Modify to the new domain.
  • Click the Save Config button.

Step 6: Set values for the MAGE_RUN_TYPE and MAGE_RUN_CODE

Open the index.php file under application root directory

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

by these codes:

switch($_SERVER[‘HTTP_HOST’]) {
case ‘website.vn’:
$mageRunCode = ‘base’;
$mageRunType = ‘website’;
break;
case ‘website.us’:
$mageRunCode = ‘second’;
$mageRunType = ‘website’;
break;
}
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $mageRunCode;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $mageRunType;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

Step 7: Test and See the results
Run the comment line following:

  • php bin/magento cache:flush
  • Go the domains website.us and website.vn
Last modified: 06.06.2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.