1

I am trying to have two different store views with different themes but has the same catalog and settings.

default store view: website.co.uk second store view should have: migrate.website.co.uk enter image description here

Both the store views share the same website and store. it is only the front end which changes.

I have created a sub domain of the main domain I have copied .htaccess and index.php from website.co.uk to migrate.website.co.uk and modified index.php file as below:

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

replacing

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

.

I have also added two lines at the start of htaccess file:

SetEnvIf Host .migrate.website.co.uk. MAGE_RUN_CODE=migrate SetEnvIf Host .migrate.website.co.uk. MAGE_RUN_TYPE=store

when check the migrate.website.co.uk it shows me a blank page with 500 error. what is wrong in the code?

1
  • do you mean I still need to copy both index.php and .htaccess into subdomain directory and configure the virtual host's file? I am using plesk and have created the subdomain, my virtual hosts file looks like below: I have two files under my sites-available: 000-default.conf default-ssl.conf i will have to edit both default and ssl conf files. port 7080 and 7081. what if i am using website.co.uk/newweb/ as my second store by creating a new folder under magento root. can i just place the environment variables on htaccess file on website.co.uk ? like below: SetEnvIf Host .*newstore.* MAGE_RUN_COD Commented Jul 16, 2018 at 8:43

2 Answers 2

0

I wouldn't recommend modifying the index.php.

This is a core file, meaning it'll simply get overwritten the next time you update Magento.

Since you're using .htaccess files I'm assuming you run apache.

In that case, you can use a virtual host configuration to share the website's files in the same directory:

<VirtualHost *:80>
    ServerName          website.co.uk
    ServerAlias         "www.website.co.uk"
    DocumentRoot        /path/to/your/magento2/
    SetEnv MAGE_RUN_CODE "default"
    SetEnv MAGE_RUN_TYPE "store"
</VirtualHost>

<VirtualHost *:80>
    ServerName          migrate.website.co.uk
    DocumentRoot        /path/to/your/magento2/
    SetEnv MAGE_RUN_CODE "migrate"
    SetEnv MAGE_RUN_TYPE "store"
</VirtualHost>
-1

I used the following solution to separate the domain with different stores and websites.

Step 1: Please add below code to <magento_root>/app/etc/env.php file

'website_configuration' => [
    [
        'domain' => 'website.co.uk',
        'run_code' => 'base',
        'run_type' => 'website'
    ],
    [
        'domain' => 'migrate.website.co.uk',
        'run_code' => 'store1',
        'run_type' => 'store'
    ]
],

Step 2: Update <magento_root>/pub/index.php file

$prebootstrap = Bootstrap::create(BP, $_SERVER);

// Setup multi-store urls
$params = $_SERVER;

$objectManager = $prebootstrap->getObjectManager();
// Get website configurations from env.php
$deploymentConfig = $objectManager->get('\Magento\Framework\App\DeploymentConfig');
$websiteConfiguration = $deploymentConfig->get('website_configuration');

foreach ($websiteConfiguration as $website) {
    if ($_SERVER['HTTP_HOST'] === $website['domain']) {
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $website['run_code'];
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $website['run_type'];
    }
}
// End Setup multi-store urls
$bootstrap = Bootstrap::create(BP, $params);

Step 3: Update <magento_root>/pub/get.php file

$prebootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

// Materialize file in application
$params = $_SERVER;
// Setup multi-store urls
$objectManager = $prebootstrap->getObjectManager();
// Get website configurations from env.php
$deploymentConfig = $objectManager->get('\Magento\Framework\App\DeploymentConfig');
$websiteConfiguration = $deploymentConfig->get('website_configuration');

foreach ($websiteConfiguration as $website) {
    if ($_SERVER['HTTP_HOST'] === $website['domain']) {
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $website['run_code'];
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $website['run_type'];
    }
}

if (empty($mediaDirectory)) {
    $params[ObjectManagerFactory::INIT_PARAM_DEPLOYMENT_CONFIG] = [];
    $params[Factory::PARAM_CACHE_FORCED_OPTIONS] = ['frontend_options' => ['disable_save' => true]];
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
// End Setup multi-store URLs

Step 4: Update base URL from admin > Stores > Configurations > Choose website or Store Scope > General > Web > Base URLs > Base URL

Step 5: Change the Base URL and save the configuration.

Step 6: Clear the cache.

I used the above solution on my dev setup and Live site, it works for me.

Please apply this solution if it works for you!

Thank you!!!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.