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.

Tags (2)
5 REPLIES

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.

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.

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