1

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.

Hartwig
  • 111
  • 2
  • are you saying that when accessing www.example.com/products the mapping working fine but when access www.example.com/products/tshirt.html it not works? the header mage-run-code not shown or the $store_language is false? Please explain more. When i see the regex in map block its should be fine. – Ilham Sulaksono Jan 13 '18 at 10:10
  • Thanks Ilham Sulaksono. I tried to clarify my question with an edit. – Hartwig Jan 14 '18 at 10:28
  • wow, that's a strange behavior. I test it with my own nginx, and it work well. I think the error is not in the regex – Ilham Sulaksono Jan 14 '18 at 14:51
  • Thank you very much for letting me know that. I will retest everything on Monday and come back with my findings. – Hartwig Jan 14 '18 at 14:54

0 Answers0