I have tried numerous ways to achieve this task. I would like to thank @matias-hidalgo for his contributions, although I did not understand his answer at first read :).
Here is the scenario. We have two different websites, and each website has two different store views as follows:
Website 1
- Website 1 (E-commerce)
- Website 1 (Venda Assistida)
Website 2
- Website 2 (E-commerce)
- Website 2 (Venda Assistida)
In my solution, we are going to change some configuration in Magento Admin. Then we are going to create some sub-folders, and finally we are going to modify nginx.conf
.
First of all, we need to make some configuration change in the Magento Admin. Go to Stores
-> Configuration
-> General
-> Web
. We need to change Base URLs for each store view.
For Default Config
Please provide the following configuration for default config.

For Website 1 (E-commerce) and Website 1 (Venda Assistida)
Please provide the following configuration for all Website 1 store views.

For Website 2 (E-commerce) and Website 2 (Venda Assistida)
Please provide the following configuration for all Website 2 store views.

Secondly, we need to create website1
and website2
folders in the /pub
directory. In the final, you should have the following folders:
MAGENTO_ROOT/pub/website1
MAGENTO_ROOT/pub/website2
Copy the pub/index.php
file into these directories. Then we will make some changes in MAGENTO_ROOT/pub/website1/index.php
and MAGENTO_ROOT/pub/website2/index.php
.
Content of MAGENTO_ROOT/pub/website1/index.php
I have only changed 3 lines:
1st Line: require __DIR__ . '/../../app/bootstrap.php';
2nd Line: $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website1';
3rd Line: $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
<?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;
use Magento\Framework\App\Filesystem\DirectoryList;
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] = 'website1';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];
$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);
For the final touch, we need to modify nginx.conf
in your MAGENTO_ROOT directory. Please put the following configuration into your nginx.conf
.
location /website1 {
root /website1;
if (!-e $request_filename) {
rewrite ^/(.*)$ /website1/index.php last;
break;
}
}
location /website2 {
root /website2;
if (!-e $request_filename) {
rewrite ^/(.*)$ /website2/index.php last;
break;
}
}
After all this configurations and modifications, you will be able to use websites as sub-folders. I hope it helps.