- Go to
Admin > Stores > All Stores
- Click >
Create Web Site
- In the Name field, enter store name.
- e.g.
Japan
- e.g.
- In the Code field, enter a unique string without spaces and >
Save Web Site
- e.g.
super_jp
- e.g.
- Create Store
- Create Store View
- Go to
Stores > Configuration
- Select the website we just created.
- Go to Web & change both Base URLs & Base URLs (Secure)
- e.g.
Base URL: http://example.com/
Base Link URL: {{unsecure_base_url}}jp/
- ... same goes for Base URLs (Secure)
- e.g.
- Save. Clear Cache. Reindex.
-
Create a subfolder with the desired name.
- e.g.
/jp/
- e.g.
-
Copy
index.php & .htaccess
from root (!important copy both files) -
Open
index.php
clear everything inside it and paste:require realpath(__DIR__) . '/../app/bootstrap.php'; $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'super_jp'; // change this with the code you chose in step. 4 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; // store or website $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);
-
Save. Clear Cache. Reindex.
-
Enjoy your new website inside a subdir.
For me this is how I got websites working.
I've got www.example.com pointing to my doc root where the code base lives. In the doc root, I've got a subdir named sub1. In Magento, I've created a new website and set the base URLs for the new website to www.example.com/sub1/. I also had to set the static and media files base URLs to 'www.example.com/pub/static/' and 'www.example.com/pub/media/', respectively, otherwise the css and js wouldn't load.
Then like in the original solution, copy index.php and .htaccess into /sub1, open up the new index.php and copy the code from the original post, being sure to set PARAM_RUN_TYPE to 'website' and PARAM_RUN_CODE to the new website's code. Flush the cache and enjoy.