The question:
Is it possible to run two Magento 2 websites on a single domain? I want to share the user between this websites. but want to redirect them to different stores (same URL – without store code) after they login based on their user group. That two store will be having same catalogs and identical store view.
I’m just doing this for separate user experience, like to make available different payment method, shipping and catalog visibility based on the user group, that is not available in magento base setup.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
here is the answer
https://gist.github.com/thagxt/0f605f0a8a95c79302db0d2f04383788
we can create separate store in sub directory, so they run on same domain (no sub domain) and there is no need to make change in httpd or .htaccess
Method 2
There’s another way to do that, in Stores > Settings > Configuratio >web:
- Set your new site’s url to that of the base_url(ex: www.website.com/)
- Set the option of ‘add store Code in URLs’ on.
Method 3
- Magento v2.4.*
- LAMPP stack
- OS – Ubuntu
Magento 2 single domain multi website
-
Create multiwebsite in magento2 and set base url /fr , /mx
-
Create sub directory inside pub dir
-
Copy pub/.htaccess and pub/index.php into sub dir
-
Update pub/fr/index.php
<?php use MagentoFrameworkAppBootstrap; 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[MagentoStoreModelStoreManager::PARAM_RUN_CODE] = 'DFR'; //Webite code as same in admin panel $params[MagentoStoreModelStoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $params); $bootstrap = Bootstrap::create(BP, $params); /** @var MagentoFrameworkAppHttp $app */ $app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class); $bootstrap->run($app);
-
Create symlinks for static, media and error files
cd pub/fr ln -s ../media media ln -s ../static static ln -s ../opt opt ln -s ../errors errors
Clear cache and redeploy
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0