cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.4.2 multistore with different domains not working

Magento 2.4.2 multistore with different domains not working

Hi guys,

 

I need to advice with following:

 

I have two domains .cz and .com. I set up these two domains in my admin https://snipboard.io/5GESou.jpg 

Now .com is still redirect to .cz , but the redirection is not activated. 

 

.com is a parked domain .cz and share a same document root (screen attached). I don't know what to do and I need to domain work correctly:

 

1) .cz - works now fine

2) .com - has two store views

a) EN - Which is default for english speaker (any slash .com/en is not necessary)

b) DE - I want it to be .com/de 

 

 

 

Magento 2.4.2-p1

 

Thank you for your help.

V.

4 REPLIES 4

Re: Magento 2.4.2 multistore with different domains not working

Hi there,

 

I had the very same problem with MAGENTO 2.1 . After reading thousands (literally) of blogs, tutorials and websites I figured it out by sticking a few lines of code.

1 : Do not touch the .HTACCESS file. There's nothing to modify in there.

2 : Open INDEX.PHP and replace the following code

$bootstrap = \Magento \Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

by this code :

$params = $_SERVER;

switch($_SERVER['HTTP_HOST']) {

        case 'Domain1.com':
        case 'www.Domain1.com':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'Website_code1';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;


        case 'Domain2.com':
        case 'www.Domain2.com':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'Website_code2';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;
    }

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

There's 4 things to replace in the above code.

  1. domain1.com and www.domain1.com = Your domain name for the first store (Should be the BASE store).
  2. Website_code1 = Website code for the first store.
  3. domain2.com and www.domain2.com = Your domain name for the second store
  4. Website_code2 = Website code for the second store.

Re: Magento 2.4.2 multistore with different domains not working

Hi there,

 

I had the very same problem with MAGENTO 2. . After reading thousands (literally) of blogs, tutorials and websites I figured it out by sticking a few lines of code.

1 : Do not touch the .HTACCESS file. There's nothing to modify in there.

2 : Open INDEX.PHP and replace the following code

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

by this code :

$params = $_SERVER;

switch($_SERVER['HTTP_HOST']) {

        case 'Domain1.com':
        case 'www.Domain1.com':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'Website_code1';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;


        case 'Domain2.com':
        case 'www.Domain2.com':
             $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'Website_code2';
                         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        break;
    }

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

There's 4 things to replace in the above code.

  1. domain1.com and www.domain1.com = Your domain name for the first store (Should be the BASE store).
  2. Website_code1 = Website code for the first store.
  3. domain2.com and www.domain2.com = Your domain name for the second store
  4. Website_code2 = Website code for the second store.

Read more here!

Re: Magento 2.4.2 multistore with different domains not working

Hi,

 

thank you, but how should I write the URLs address

 

 case 'Domain1.com':
        case 'www.Domain1.com':

In my case

 

case 'Kouzloloutek.cz' :

              case 'www.kouzloloutek.cz ' :    

 

Is it correct, please?

 

Re: Magento 2.4.2 multistore with different domains not working

Hi,

 

thank you, but how should I write the URLs address

 

 case 'Domain1.com':
        case 'www.Domain1.com':

In my case

 

case 'Kouzloloutek.cz' :

              case 'www.kouzloloutek.cz' :    

 

Is it correct, please?