3

I'm trying to implement multiple website in Magento 2.1.3 For that, I have created an extra website store and store view

My site URL is like www.example.com

My subdomain is www.kw.example.com(where kw is the code of new website).

I have create sub domain in my domain and point this in to a new folder in Magento root folder which contain the index file of new website. And i have changed the website URL and secure BASE URL as www.kw.example.com but when i try to access to this URL its redirecting in to www.example.com

2 Answers 2

2

Follow this and comment for any issue:

  1. Verify your desired domain name points to the server.
  2. Create a secondary domain for your new store.
  3. Using either FTP or SSH, copy the .htaccess and index.php files from your Magento installation to the document root of your new domain.
  4. Open the index.php file that you just copied and edit the last lines of the file as follows:

Attention: Change newstore to the code that you wrote down when you created the new website above.

Replace:

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

With:

require __DIR__ . '/app/bootstrap.php'; $params = $_SERVER; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstore'; $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication('Magento\Framework\App\Http'); $bootstrap->run($app);

  1. Using SSH, create the following symbolic links in the document root of your new domain, and replace the path below with the full path to the document root of your Magento Installation:

ln -s /home/example/example.com/html/app/ app

ln -s /home/example/example.com/html/lib/ lib

ln -s /home/example/example.com/html/pub/ pub

ln -s /home/example/example.com/html/var/ var

Update in Your case:

Replace ln -s /home/example/example.com/html/app/ app with ln -s /var/www/html/m2/example.com/app/ app

13
  • I have followed this step but i dont have idea the step you mentioned in step 5 how can i do that
    – amith lal
    Jun 30, 2017 at 5:29
  • Thats important step. Do you have SSH access of site?
    – Jarnail S
    Jun 30, 2017 at 5:32
  • WIth SSH, Go to root folder of www.kw.example.com and execute step [5]. "example/example.com/" is your main domain here. This is where your main site is working.
    – Jarnail S
    Jun 30, 2017 at 5:37
  • My path to root is like this /var/www/html/m2/ so imay run like this ln -s /var/www/html/m2/app/ app is it?
    – amith lal
    Jun 30, 2017 at 5:55
  • NO. Do one thing. Create a file: test1.php and upload this to root of your site. Put this code in file: <?php phpinfo(); ?>. Access this file from briwser: ie . example.com/test1.php. This will open details. Search for "$_SERVER['SCRIPT_FILENAME']" . Here you will find the path. Comment that here
    – Jarnail S
    Jun 30, 2017 at 6:00
0

Here is example you could setup:

your M2 site root folder:

/var/www/m2

your domains:

v1.example.com
v2.example.com
  • create 2 websites (website codes: sitev1 and sitev2)

  • update website domains under System > Configuration > Web.

  • update virtual hosts on your server and setup environment variables.

Example for apache

SetEnvIf Host .*v1.example.com.* MAGE_RUN_CODE=sitev1
SetEnvIf Host .*v1.example.com.* MAGE_RUN_TYPE=website
SetEnvIf Host .*v2.example.com.* MAGE_RUN_CODE=sitev2
SetEnvIf Host .*v2.example.com.* MAGE_RUN_TYPE=website

Notice: if you have PHP running in CGI mode on your server you will need to update index.php with this line:

/* Load Stores via SERVER REDIRECT_ */
$params = $_SERVER;
if (isset($params['REDIRECT_' . \Magento\Store\Model\StoreManager::PARAM_RUN_TYPE])) {
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = $params['REDIRECT_' . \Magento\Store\Model\StoreManager::PARAM_RUN_TYPE];
}
if (isset($params['REDIRECT_' . \Magento\Store\Model\StoreManager::PARAM_RUN_CODE])) {
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = $params['REDIRECT_' . \Magento\Store\Model\StoreManager::PARAM_RUN_CODE];
}
/* END */

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

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.