2

I need to create a new store for my e-commerce (not a new website, not a new store front) for B2B.

Now, my e-commerce is active on mobiroloshop.com (B2C) and I want the new store on b2b.mobiroloshop.com.

I've followed several tutorials but still have problems. If I create an alias (parked domain) on cPanel for B2B, when I type b2b.mobiroloshop.com,

I'm redirected to mobiroloshop.com. I tried both to change .htaccess file (following step-by-step this tutorial https://www.cloudways.com/blog/create-and-configure-multistore-magento-2/) and to use a switch statement on my index.php (to switch B2B or B2C based on $_SERVER content).

Can someone please help me with this struggling issue?

This is my Magento Stores configuration

My Magento store configuration.

4

3 Answers 3

0

I had the same problem. What's missing is the environment variable.

Add to your .htaccess file

SetEnvIf Host b2b\.mobiroloshop\.com MAGE_RUN_CODE=b2b
SetEnvIf Host b2b\.mobiroloshop\.com MAGE_RUN_TYPE=store

If your server is Nginx, check: http://devdocs.magento.com/guides/v2.0/config-guide/multi-site/ms_nginx.html

Regards

0

I solved this problem setting the correct envioroment variables and using de env_mode of apache.

<VirtualHost *:80>
    ServerName msite1.domain.com
    DocumentRoot /var/www/magedemo/pub

    <Directory /var/www/magedemo/pub/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName msite2.domain.com

    DocumentRoot /var/www/magedemo/pub

    <Directory /var/www/magedemo/pub/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>

    SetEnv MAGE_RUN_CODE "s2"
    SetEnv MAGE_RUN_TYPE "store"
</VirtualHost>

The code "s2" is the code configured for the webview.

This is my configuration using Magento 2.1.7:

enter image description here

0

This is possible through your index.php

for apache use index.php and for nginx use pub/index.php

example switch including development suffix support:

if(!isset($_SERVER['MAGE_RUN_CODE']) || !$_SERVER['MAGE_RUN_CODE']) {
    if (preg_match('/^(.+)\.(developmentsuffix.com)/', $_SERVER['HTTP_HOST'], $match)) {
        $website = $match[1];
    } else {
        $website = $_SERVER['HTTP_HOST'];
    }

    switch ($website) {
        case "example.com":
        case "www.example.com":
            $_SERVER['MAGE_RUN_CODE'] = "website_code";
            $_SERVER['MAGE_RUN_TYPE'] = "website";
            break;

        case "sub.example.com":
            $_SERVER['MAGE_RUN_CODE'] = "website_code2";
            $_SERVER['MAGE_RUN_TYPE'] = "website";
            break;

        default:
            $_SERVER['MAGE_RUN_CODE'] = "website_code";
            $_SERVER['MAGE_RUN_TYPE'] = "website";
    }
}

put the code just above this line:

$params = $_SERVER;

and don't forget to set the correct base urls in the Magento Configuration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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