In Magento 2,

How to have the default store to be set on domain.com and other stores to be in directory structure urls like: domain.com/uk, domain.com/de, ..

First approach: There is the admin configuration Admin > Stores > Configuration > GENERAL > Web > Url Options > Add Store Code to Urls = Yes. But it's a global configuration and can't be set on website level or store level.

Now, what I can have is domain.com/[default_store_code]/*. Actually if I visit domain.com it will render urls inside the page as domain.com/[default_store_code]/path_to_category, ..

Is it something that I miss here ?

In Nginx specifically I'm interested about. I don't want to add declarations in Nginx conf to redirect domain.com/defaut_store_code/* to domain.com/*. I don't like it and I don't believe there should be an additional redirect just to stay on domain.com/* URL.

Second approach: Another approach that i'm looking at is to set Add Store Code to Urls = No and have in admin configuration Base Url set to domain.com in default store configuration level. And on store uk configuration level to have Base Url set to domain.com/uk/ The last part it would be to write something in Nginx conf to set store codes and website code by url. Like if I'm on domain.com/uk/* than set MAGE_RUN_CODE to uk

Update: I'm testing the second approach with Add Store Code to Urls = No. I'm using in Nginx the conf bellow to make Magento 2 aware of the store codes. The static resources like css, js and .html were not working. I set in global configuration Base URL for Static View Files = http://domain.com/static/ and Base URL for User Media Files http://domain.com/media/

Inspired from here: Magento 2 multi website url setup

# in http context of conf
map $request_uri $MAGE_RUN_CODE {
    default   default;
    ~^/uk  uk;

map $request_uri $MAGE_RUN_TYPE {
    default   store;

server {
    set $MAGE_MODE developer;
    fastcgi_param  MAGE_MODE $MAGE_MODE;

    listen 8080;
    server_name domain.com;
    set $MAGE_ROOT /[../path to magento 2];

    # I have tried several try_files and didn't do nothing

    include /[../path to magento 2]/nginx.conf.sample;

    #location ~ (index|get|static|report|404|503)\.php$ {
    #   fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;
    #   fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;

This works for me if I put it in the file /[../path to magento 2]/nginx.conf.sample

    # Search 'location' line bellow and add the 2 fastcgi_param lines from bellow
    location ~ (index|get|static|report|404|503)\.php$ {
       fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;
       fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;

Further I'm looking in Magento 2 why it doesn't like to have a directory path before the controller part in URL. And I'll also explore those try_files in conf.

Update 2

I've added as an experiment in \Magento\Store\App\Request\PathInfoProcessor::process()

if ($store->isUseStoreInUrl()) {
} else {
    if ($store) {
       $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
       return $pathInfo;

Store switcher on the page doesn't work well but it rendered the pages ok: homepage,category page, product page. It still needs solid research until it's good.

Thank you

  • Did you have success with your approach? – FaHu Jul 25 '17 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.