【发布时间】:2016-11-01 19:26:13
【问题描述】:
我有一个 nginx 情况,需要一些帮助。
故事:
- 曾经有一个网站,我们称之为 website.com,其中创建了虚拟子域。 subdomain.website.com 等每个 URL 都是动态创建的(有 subdomain.website.com、anothersubdomain.website.com、someothersubdomain.website.com 等)
- 每个创建的子域都有一个内部结构,例如 subdomain.website.com/some/internal/structure/ 或 subdomain.website。 com/some-file.html
- 现在,所有者想要永久移动主网站内的所有子域,例如这个 website.com/sub-subdomain/ 或 website.com/sub-subdomain/some/internal/structure 或 website.com/sub-subdomain/some-file.html
我现在掌握的是捕获子域并将它们重定向到主网站内的规则,如下所示:
if ($http_host !~ "^www.website.com"){
set $rule_0 1$rule_0;
}
if ($http_host ~ "([^.]+).website.com"){
set $rule_0 2$rule_0;
set $bref_1 $1;
}
if ($rule_0 = "21"){
rewrite ^/(.*) http://www.website.com/sub-$bref_1/ permanent;
}
问题是,如果我有一个像 subdomain.website.com/some/internal/structure/ 或 subdomain.website 这样的 URL .com/some-file.html 我用上面的代码 sn-p 得到的只是这个 www.website.com/sub-subdomain/ 我失去了子域结构的其余部分(“some/internal/structure/”或“some-file.html”部分 - 当然没有引号)
我应该如何更改上面的代码 sn-p 以便保留上面提到的丢失的部分?
提前感谢您的帮助!
【问题讨论】:
标签: nginx url-rewriting