Showing results for 
Search instead for 
Did you mean: 

Multiple store views with multiple domains

Multiple store views with multiple domains

I have set up magento 2 with 2 store views: language A (with code A) and language B (code B).

I have two domains with different country extensions: and mysite.bbb

I have set up virtual hosting so both domains point to the same place.

I have set up both base-urls in backend appropriately. 



What I want to do is is now obvious: shows store view A and mysite.bbb shows storeview B


My guess and what I've read online is that now I just need to configure .htaccess


However this does not work:



SetEnvIf Host www\.mysite\.aaa MAGE_RUN_CODE=A
SetEnvIf Host www\.mysite\.aaa MAGE_RUN_TYPE=store

SetEnvIf Host www\.mysite\.bbb MAGE_RUN_CODE=B
SetEnvIf Host www\.mysite\.bbb MAGE_RUN_TYPE=store


Can I use different domains for different storeviews or do I need to create two stores?


Re: Multiple store views with multiple domains

How to set MAGE_RUN_CODE and MAGE_RUN_TYPE to an Apache webserver:

Re: Multiple store views with multiple domains

OK, I see what is missing.

I have a web hosting with cpanel that as far as i know does now allow me to write to the apache config file.


Could I only use RewriteRule in .htaccess?


Re: Multiple store views with multiple domains

I would really appreciate some help, because I have tried 100 different things and nothing works Smiley Sad


Now I have set up two domains mydomain.a and mydomain.b,  with public folders







/a/public_html/index.php looks like



$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'a';
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');


and /b/public_html/index.php looks the same except that I have 'b' in the 3rd line.


in /b/public_html/ I have set up symbolic links to all folders in /a/public_html/ (app, bin, dev, pub,...).


I have two stores views with codes "a" and "b". And the "base URL" properties for store view "a" is "http://www.mydomain.a" and for "b" "http://www.mydomain.b".


But when I go to mysite.a it looks fine, but when I go to mysite.b it redirects to mysite.a and language is a, not b.
And when I go to either mysite.b/admin or mysite.a/admin it starts to loop from a to b and I get "This website has a redirect loop".


Isn't this super weird? Perhaps if I have two full installations of Meganto 2 and just a common database, would this work?