Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariamghalleb/01fc3bb4eb3780b41ca1cbbd4cdd42cf to your computer and use it in GitHub Desktop.
Save mariamghalleb/01fc3bb4eb3780b41ca1cbbd4cdd42cf to your computer and use it in GitHub Desktop.
Set up Magento 2 multiple websites in sub directories

Set up Magento 2 multiple websites in sub directories

  1. Go to Admin > Stores > All Stores
  2. Click > Create Web Site
  3. In the Name field, enter store name.
    • e.g. Japan
  4. In the Code field, enter a unique string without spaces and > Save Web Site
    • e.g. super_jp
  5. Create Store
  6. Create Store View
  7. Go to Stores > Configuration
  8. Select the website we just created.
  9. 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)
  10. Save. Clear Cache. Reindex.

Doing stuff in server root

  1. Create a subfolder with the desired name.

    • e.g. /jp/
  2. Copy index.php & .htaccess from root (!important copy both files)

  3. 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);
    
  4. Save. Clear Cache. Reindex.

  5. Enjoy your new website inside a subdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment