0

I need to create many different magento 2.3 shops as subdomains of the main shop www.domain.com; eg shop1.domain.com, shop2.domain.com, shop3.domain.com, shop3.domain.com

All those subshops will share the exact same content, products and storeviews (content in different languages using subdirectories /en /fr /de etc) of the main domain and my goal is to not create a different magento website or magento storeview for each of such subdomains. I'll customize just some graphic of the subdomains by loading a different theme/css based on the HTTP HOST env variable.

Can you tell me how to achieve this?

I've now configured nginx so that all the subdomains are mapped to the same document root, but when now I load a.domain.com I get automatically redirected to www.domain.com

In my index.php I've added the lines below before ($bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);):

switch($_SERVER['HTTP_HOST']) {

    case 'shop1.domain.com':
         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = '<default_storeview_code>';
         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    break;

}

I want that if I type shop1.domain.com in the browser address bar I'm not redirected to the main url set for the storeview www.domain.com (this is my current problem).

Thank you!

0

You have to make necessary change in nginx settings not in magento 2 index.php file

9
  • In nginx I've all subdomains working and mapped to the same document root. The problem is that once I visit a subdomain I get redirected to the main domain (and this happens due to a magento redirect, not to nginx - verified). It doesn't seem a nginx issue. In any case, if you thing that there is something to set in nginx, what should I change?
    – Tom
    Jul 5 '20 at 8:26
  • I will provide my changes what I did. I also have multiple subdomains running on same instance.
    – Sheba
    Jul 6 '20 at 18:10
  • Please view my changes for the nginx by using this link: drive.google.com/file/d/1eV1IAftwnJZFpKKOO4M-jtfBzay63SC6/…
    – Sheba
    Jul 7 '20 at 6:14
  • I've checked the code and I don't see anything special, except that you're changing the index in the subdomains. Why do you repeat the codes below in the 3 locations /ca/, /english-brand/ and /canada-brand/ ? set $MAGE_ROOT /var/www/vhosts/kefdirect.com/httpdocs/pub; /* Sub Domain */ set $MAGE_MODE developer; What I want to do is only having the same website to be accessible with different hostnames and having magento not doing a redirect. I think that your solution doesn't solve this problem. Am I wrong?
    – Tom
    Jul 7 '20 at 9:23
  • The way you are thinking is not possible. You can do that either by creating store or multi website
    – Sheba
    Jul 7 '20 at 18:33
0

I've found the solution: I had just to change the "Auto-redirect to Base URL" to "no" and it worked. Now I've to customize Base URLs, but at least I fixed the automatic redirect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.