Search for nginx map variables based on url or hostname + uri (not hostname)

we run Magento and before the date, depending on the host name, a variable was set to determine which store to display. An example is below.

map $http_host $storecode {
 domain.com store1_en;
 otherdomain.com store2_en;
}

Now the new stores are configured using (2 characters) a languagecode of type 'en', 'de' or 'fr' and the url becomes domain.com/en or otherdomain.com/fr.

In order for the above to work, the map search must be changed and the host of the server name should no longer be used, but rather the first part of the URL .... and also in the correct order ....

Q: How can this be achieved? Or has anyone done this before?


As a result, the following comparison is what we are looking for

  • domain.com/en => store1_fr
  • domain.com => store1_en
  • otherdomain.com = > store2_ru

:

map $uri $storecode {
 ^domain.com/en.* store1_fr;
 ^domain.com.* store1_en;
 ^otherdomain.com.* store2_en;
}

map $http_host$uri $storecode {
 ^domain.com/en.* store1_fr;
 ^domain.com.* store1_en;
 ^otherdomain.com.* store2_en;
}

MAP MAP?

$uri ( , ..)

+4

All Articles