多语言存储为 nginx 上的符号链接子目录,返回“无页面路由”
-
12-12-2019 - |
题
我们需要使用以下命令来设置我们的多语言商店 subdirectory/symlink
描述的方法 这里. 。(阅读原因@底部)
我们是如何做到的。 我们将index.php复制到一个子目录并符号链接所有文件夹。这 base url
被设置为 domain.com/en
问题/疑问现在,当我打开domain.com/en 时,我可以看到该网站,并且显示英文版本。唯一的问题是所有类别和产品链接都会产生“无页面路由”错误。而不是显示类别或产品。现在怎么会这样呢?
例子所以 https://domain.com/en/funkyshoes
没有打开 funkyshoes 类别,funkyshoes 也没有 https://domain.com/funkyshoes
对于这个问题。https://domain.com/en/funkyshoes
返回 => no route to page
https://domain.com/funkyshoes
返回 => https://domain.com/en
为什么不?因为我们有超过 1 个多重商店,无法为每个商店提供像 en/de/fr 这样的 lang store_code,而且我们有一个多重商店,每个商店具有不同的域,而另一个则使用主域中的 /en、/de、/fr 方法。
解决方案 2
更好的解决方案是:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite /(../)? /$1index.php?$args;
}
因为我们对目录|结账|客户有一些特殊的位置规则。问题在于,它们都引用了 @rewrite - 这样我们就必须重写所有设置的位置命令,以便与 /en 以及后来的 /fr 和 /de 进行单独的匹配......
因此,我们想出了最简单的后备重写,首先测试 /,然后测试 /(两个字母的代码)......并在此基础上重写
似乎工作正常
此外,需要更改 store_code 查找。由于 /en,http_host 变量或服务器变量不再起作用。
可以在这里找到可能的解决方案:https://stackoverflow.com/questions/30078679/nginx-conf-w-multiple-maps-to-same-variable
其他提示
这是 NGINX 的问题。
将其添加到conf文件中解决了我们的问题
location /en {
rewrite ^/en(.*)$ /en/index.php last;
}