I'm trying to write a nginx config that adds a custom header and pass a variable using fastcgi_param based on two variables that are calculated using map, based on $uri and $http_host.
map $uri $STORE_LANGUAGE {
~^/products en;
~^/de/produkte de;
~^/fr/produits fr;
~^/hu/termekek hu;
}
map $http_host $MAGE_RUN_CODE {
www.example.com example_com_;
}
server {
listen 80;
add_header mage-run-code $MAGE_RUN_CODE$STORE_LANGUAGE;
...
location ~ \.php$ {
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE$STORE_LANGUAGE;
fastcgi_param MAGE_RUN_TYPE store;
}
The goal is to be able to pass the mage-run-code to Magento 2.2 via fastcgi_param MAGE_RUN_CODE (and have the header as an easy way to debug for now). This way Magento knows which store view to serve the visitor.
The above code works for www.example.com/products. (Expected behaviour: example_com_en)
What do I have to change in the regexp for STORE_LANGUAGE in order for www.example.com/products/tshirt.html to work as well?
EDIT: For www.example.com/products $MAGE_RUN_CODE is calculated correctly ("example_com_") as is $STORE_LANGUAGE ("en") resulting in "example_com_en".
For www.example.com/products/tshirt.html $MAGE_RUN_CODE is calculated correctly (based on $http_host). But $STORE_LANGUAGE returns empty. Thus the combination of $MAGE_RUN_CODE$STORE_LANGUAGE is "example_com_" and not the expected "example_com_en" for the tshirt.html URL.