cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Multi Site with Subdirectories Setup

Magento 2 Multi Site with Subdirectories Setup

I'm in the process of rebuilding a clients site from their Magento 1.3 install to Magento 2.3 and am having a load of trouble setting up the multi site aspect... I've spent weeks googling and trying different solutions to no avail, so thought I'd see if there was a definitive guide out there (or somebody knowledgable enough to guide me through the setup) as it's driving me nuts!

What I'm trying to do is recreate the URL structure here: www.sonic8.com where you land on a CMS page with links to various territories all listed as sub directories of the main URL (i.e. sonic8.com/uki/ etc.) Each of these is a separate site with separate cart etc. This was simple in Magento 1 and fully documented but for some reason Magento 2 is proving a complete nightmare!

To document what I've done: I've got a fresh server install with a dedicated Magento provider that I'm accessing via an updated local hosts files so all the URL's etc. are exactly as they'l be when the site switches. I've created the websites, stores and store views in Magento. Setup the categories (root and sub). Updated the configuration to the new URL's for each site. Assigned a new homepage to the views. Created a new DIR in the root for each URL. Copied and updated the index.php files and copied over the .htaccess to this directory and I'm still getting nothing, nada, nish... Not a **bleep** thing!!! Blank screen when I try and access the www.mysite/uki/ url...

Looking over the various index files that are banded around it seems that there have been changes to the code on this since its release and perhaps I also need to edit the .htaccess but all the info I can currently find relates to subdomains and isn't working!

If anyone could point me in the right direction I'd appreciate it as this is driving me nuts!

Thanks

6 REPLIES 6

Re: Magento 2 Multi Site with Subdirectories Setup

Hello @duncan_eagles ,

 

Did you try to add the "MAGE_RUN_TYPE" and "MAGE_RUN_CODE" to your server(apache) ?

 

Where you can find more info about here;

https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_apache.html

Re: Magento 2 Multi Site with Subdirectories Setup


@WoutK wrote:

Hello @duncan_eagles ,

 

Did you try to add the "MAGE_RUN_TYPE" and "MAGE_RUN_CODE" to your server(apache) ?

 

Where you can find more info about here;

https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_apache.html

 

Unfortunately that's the issue... I have looked into adding the virtual hosts on Apache 2.4 but cannot for the life of me find the etc/httpd/conf/httpd.conf file!!!

 

Also (once I can find this - assuming it's there!) would i set the document roots as mysite.com/uki/? This seems dedicated to subdomains rather than subfolders??

 

Thanks,

 

Duncan


 

Re: Magento 2 Multi Site with Subdirectories Setup

 

Assuming that you have apache, the directory and file should be ;

/etc/apache2/sites-available/000-default.conf

and

/etc/apache2/sites-available/default-ssl.conf 

 

You can add your own named files like;

 /etc/apache2/sites-available/example.com.conf

 

But then you need to enable or disable them with;

a2ensite example.com
a2dissite example.com

 

 After all you need to restart apache

sudo service apache2 restart

Re: Magento 2 Multi Site with Subdirectories Setup

We use symlinks to serve stores like /nl, /en, /fr.

 

sitea.be/nl, sitea.be/fr, sitea.be/en

siteb.be/nl, siteb.be/fr, siteb.be/en

 

We created our symlinks with:

 

for STOREFRONT in en fr nl; do   ln -s /data/web/public /data/web/public/$STOREFRONT; done

note: /data/web/public is pointing to the pub folder of Magento2.

 

We have additional config on nginx;

location ~ ^/(?<uri_prefix>(nl|en|fr)) {

index index.php index.html index.htm;
try_files $uri $uri/
/$uri_prefix/index.php?$args;

    location ~ \.php$ {
        echo_exec @phpfpm;
    }   
}

and runmaps:

map $host $default_storecode {
	default sitea_nl;
	sitea.be sitea_nl;
	www.sitea.be sitea_nl;
	siteb.be siteb_fr;
	www.siteb.be siteb_fr;
}

map $host$request_uri $storecode {
	default $default_storecode;
	~^sitea.be/nl sitea_nl;
	~^sitea.be/fr sitea_fr;
	~^siteb.be/nl siteb_nl;
	~^siteb.be/fr siteb_fr;
}

Store View config

Secure Base URL: https://sitea.be/nl/

Secure Base URL for Static View Files: https://sitea.be/static/

 

pm; if you need more information.

 

 

Re: Magento 2 Multi Site with Subdirectories Setup

What does the echo_exec @phpfpm represent? 

Re: Magento 2 Multi Site with Subdirectories Setup

Here are the key steps to set up multiple stores with subdirectories in Magento 2:

 

Create separate websites, stores, and store views in Magento admin.

Set unique code and base URL with a subdirectory for each website.

Update .htaccess in each subdirectory to redirect back to parent index.php.

Update index.php in subdirectories to point back to root index.php.

Clear caches and generated/code directories after making changes.

Use different themes per website if needed.

It may require some trial and error to get subdirectory stores working properly.