
- August 5, 2021
- admin
- 0 Comments
- Magento 2
Create Multiple Websites or Stores in Magento 2 Based on Sub-folder
A single instance of Magento software can be used to start multiple websites or stores that use different Product Catalog, Content, Currencies, Domains etc… This flexible solution by Magento uses single Codebase and Admin Dashboard to install and maintain multiple websites.
There are several ways Multiple Websites or Stores could be used in Magento:
- Multiple websites on different domain (example: https://store1.com/, https://store2.com/)
- Multiple websites on sub-domains (example: https://store1.store.com/, https://store2. com/)
- Multiple websites on different path (example: https://store.com/store1, https://store.com/store2)
These stores can be setup differently in Magento 2:
- Using store code
- Using sub-folder based
- Etc…
This article gives idea about setup Multiple Websites / Stores using sub-folder method.

Website – Create website when it requires separate delivery methods, payment methods, that do not share between sites. However, customer accounts will be shared between websites.
Store – Create stores when it requires for having different Product Catalog. Cart, user sessions, payment gateways, delivery methods are shared between store within website.
Store View – Store views are mainly for different layout or language and presentation for same store. Every store will have at least one store view.
Follow below steps to create Multiple Website or Stores
Step 1: Create Website
Top level scope of a site in Magento is Website.
New website can be created by following the below steps:
- Login into Magento 2 Admin
- Navigate to Stores > Settings > All Stores

- Click on Create Website

- Enter website details like Name, Code, Sort Order
- Name – Website name
- Code – Unique website code
- Sort Order – Sort order to display website order in the list (0, 1, … N)
- Save Web Site

Step 2: Create Store
- Navigate to Stores > Settings > All Stores
- Click on Create Store
- Web Site – Select website for which the store is to be created
- Name – Store name
- Code – Unique store code
- Root Category – Root Category of products to be listed in the store
- Save Store

I have created 2 additional websites/stores/store views

Step 4: Create Sub-Folders
Create sub-folders (store1, store2) under pub folder with the name of the url path (example: https://store.com/store1, https://store.com/store2) and copy index.php and .htaccess from pub folder into sub-folders store1, store2
Edit the index.php from pub/store1, pub/store2 folders to load respective website/store.
Original index.php
<?php /** * Public alias for the application entry point * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ use Magento\Framework\App\Bootstrap; 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); } $bootstrap = Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class); $bootstrap->run($app);
Edited index.php
<?php
/**
* Public alias for the application entry point
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Bootstrap;
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;
$mageRunCode = 'store1';
$mageRunType = 'website';
$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);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);
Note the edited content in bold. The above one is done for store1 folder. The same to be done for store2 folder to load store2.
Step 5: Create Links
Goto pub/store1 folder and provide soft links to app, lib, media, static and var folders. To do this, goto pub/store1 folder and run below commands.
ln -s /home/store/public_html/app/ app
ln -s /home/store/public_html/var/ var
ln -s /home/store/public_html/lib/ lib
ln -s /home/store/public_html/pub/media/ media
ln -s /home/store/public_html/pub/static/ static
Where /home/store/public_html/ is Magento root
Step 6: Change Base Urls
- Navigate to Stores > Settings > Configurations
- Select Scope as Store1 (Store2) for the website to change the Base Url
- Goto General > Web
- Edit the Base URLs and Base URLs (Secure)
- Save Config



That’s it. Now, run all the commands as below:
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:static-content:deploy en_US
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento indexer:reindex
Now you are ready to keep adding products on multiple stores and start selling.
Comment below should you require any advice or contact us for any assistance.
Leave a Comment