基于 url 或主机名 + uri(不是主机名)的 nginx 映射变量查找

snh*_*_nl 6 nginx

我们运行 Magento 并根据主机名设置一个变量来决定显示哪个存储直到日期。下面举例。

map $http_host $storecode {
 domain.com store1_en;
 otherdomain.com store2_en;
}
Run Code Online (Sandbox Code Playgroud)

现在,新商店使用(2 个字符)语言代码(如“en”、“de”或“fr”)设置,url 变为 domain.com/en 或 otherdomain.com/fr。

为了使上述工作,地图查找应该被改变,不再应该使用 servername 的主机,而是应该使用 URL 的第一部分 .... 并且以正确的顺序 ....

问题:如何做到这一点?或者以前有人这样做过吗?


因此,以下映射是我们正在寻找的

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

作为解决方案的一些想法:

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;
}
Run Code Online (Sandbox Code Playgroud)

或者我在考虑 MAP 中的 MAP?

或从 $uri 中捕获前两个字母(并且仅当它确实有两个字母以排除其他子目录请求时..)

帮助表示赞赏