cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Multi website single domain configuration

SOLVED

Magento 2 Multi website single domain configuration

Hi all, I am fighting with this issue against Magento 2, can someone have the right solution?

I am not able to configure my multi-website project.

I have one domain (testmagento.local) and I have several different websites, I need to go to the different websites through subfolders (testmagento.local/uk , testmagento.local/it , testmagento.local/us , etc)and the testmagento.local should redirect to testmagento.local/uk (the default website).

I can't use 'Add Store Code to Urls'.

I am using: Magento 2.2.3, MAMP.

I have already set up my Stores->All Stores with different codes etc. 

My basic website works (but not in the uk folder) 

I tried different solutions, like with new folders, but where? In root or in root/pub? and what exactly I have (if I have to) change in index.php or in .htaccess?

 

Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2 Multi website single domain configuration

I finally found my solution.

- Default Config -- Admin > Stores > Configuration > Web > 'Add Store Code to Urls' = No

- For every Store View -- Admin > Stores > Configuration > Web > 'Base URL' / 'Base link URL' (normal and secure) = http://namewebsite.local/uk/'

- Create one subfolder for each website (rootproject\uk , rootproject\it  etc)

- Copy index.php and .htaccess files from root and paste in every new subfolder

- In every subfolder index.php substitute this code

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

 with this

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'uk'; //Webite code as same in admin panel
$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);

- Don't change the subfolder\.htaccess files

- In order to have correct links in the default index (uk) I have also added in my root\.htaccess 

SetEnvIf Host .*goldcollagen.local.* MAGE_RUN_CODE=uk
SetEnvIf Host .*goldcollagen.local.* MAGE_RUN_TYPE=website

 

View solution in original post

9 REPLIES 9

Re: Magento 2 Multi website single domain configuration

Hi @francesca_dalla serra

 

I am hoping domain name is different for each website.

 

hopefully you are using apache2 

 

/etc/apache2/sites-available/site.name.conf file

 

 

<VirtualHost *:8080> // may be 80 port
        ServerName domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/your-dir/pub/
		SetEnv MAGE_RUN_CODE "orange" // you need to pass your website code
		SetEnv MAGE_RUN_TYPE "website"
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        <Directory /var/www/html/your-dir/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Either you need to create folder for each domain and assign that domain to that folder and index.php code 

 

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 
$params = $_SERVER;

 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'newstore'; //Webite code as same in admin panel

 $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);

Hope it will help you.

 

If help you then give kudos or mark as solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2 Multi website single domain configuration

Hi @Sunil Patel, thank you for your reply. Unfortunately, as I wrote, I have only one domain. Do you know how can I do?

Re: Magento 2 Multi website single domain configuration

Hello,

 

You need to create such a folder for that.

 

You need to assign each website wise that url.

 

Let's e.g for uk website, you need to assign yourdomain.com/uk/

 

same for another site.

 

Hope it will help you.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2 Multi website single domain configuration

Ok, thank you. I have already found some articles that are saying that. I hoped someone could explain exactly what I have to put inside the new dirs, index.php and .htaccess files, but how I have to change the content of them? Thank you very much

Re: Magento 2 Multi website single domain configuration

I finally found my solution.

- Default Config -- Admin > Stores > Configuration > Web > 'Add Store Code to Urls' = No

- For every Store View -- Admin > Stores > Configuration > Web > 'Base URL' / 'Base link URL' (normal and secure) = http://namewebsite.local/uk/'

- Create one subfolder for each website (rootproject\uk , rootproject\it  etc)

- Copy index.php and .htaccess files from root and paste in every new subfolder

- In every subfolder index.php substitute this code

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

 with this

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'uk'; //Webite code as same in admin panel
$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);

- Don't change the subfolder\.htaccess files

- In order to have correct links in the default index (uk) I have also added in my root\.htaccess 

SetEnvIf Host .*goldcollagen.local.* MAGE_RUN_CODE=uk
SetEnvIf Host .*goldcollagen.local.* MAGE_RUN_TYPE=website

 

Re: Magento 2 Multi website single domain configuration

Hi,

i am not able to configure multi stores website from your given solution.

i can blank page when i hit the url for second website.

What all i need to copy in sub directory apart from index.php and htacess file.

please help

Re: Magento 2 Multi website single domain configuration

Hi,

The solution doesn't works for me, I have the following error message :

 

Fatal error: require(): Failed opening required 'C:\wamp64\www\mywebsite.fr\folder1/app/bootstrap.php' (include_path='.;C:\php\pear') in C:\wamp64\www\mywebsite.fr\folder1\index.php on line 22

 

Is anyone has some ideas about this please ?

Re: Magento 2 Multi website single domain configuration

This solution doesn't seem to work. All the static files are getting loaded. 

Re: Magento 2 Multi website single domain configuration

Magento v2.4.*
LAMPP stack
OS - Ubuntu

 

Magento 2 single domain multi website

  • Create multiwebsite in magento2 and set base url /fr , /mx
  • Create sub directory inside pub dir
  • Copy pub/.htaccess and pub/index.php into sub dir


Update pub/fr/index.php

 

<?php
use Magento\Framework\App\Bootstrap;

try {
require __DIR__ . '/../../app/bootstrap.php';
} catch (\Exception $e) {
echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
Autoload error</h3>
</div>
<p>{$e->getMessage()}</p>
</div>
HTML;
exit(1);
}

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'DFR'; //Webite code as same in admin panel
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

$bootstrap = Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);
  • Create symlinks for static, media and error files
    cd pub/fr
    ln -s ../media media
    ln -s ../static static
    ln -s ../opt opt
    ln -s ../errors errors

    Clear cache and redeploy

Accept answer if works