【发布时间】:2019-02-05 08:30:21
【问题描述】:
我有一个这样的网址: https://example.com/home/anything/whatever
我需要重写此 URL 并将 /home/ 部分替换为来自 GeoIP 和 http-request-language 的变量: https://example.com/ch/de/anything/whatever
我在根目录上有一个位置匹配,它已经这样做了,这很有效:
location = / {
rewrite ^ $location_uri$lang permanent;
}
现在我需要这个来处理上述情况,我使用了:
location ~ /home/(.*) {
rewrite ^/home/(.*)$ /$location_uri$lang/$1/ permanent;
}
URL 的原始请求部分 ($1) 未添加到 URL 的末尾: https://example.com/ch/de//
如果我删除 2 个变量 $location_uri 和 $lang 并用修复文本 (/ch/de) 替换它们,它会起作用。
是否可以在重写中包含这些变量?
【问题讨论】:
标签: variables nginx url-rewriting