【发布时间】:2015-01-10 00:04:38
【问题描述】:
这是我的第一个 StackOverflow 问题,请多多包涵。
Nginx 为我们提供了许多不同的站点,并且我们从不同供应商的迁移客户等中获得了很多重定向。我们已经设置了一个 /includes 目录,其中包含我们迁移的每个域的重定向文件。有时,我们需要从包含获取参数的 url 编写重定向:
http://example.com/content/default.aspx?NewsId=28
为此,我们一直在一个名为 example.com-redirects 的 nginx /includes 文件中执行此操作
location ^~ /content/default.aspx {
if ($args ~ "NewsId=28") { rewrite ^ http://example.com/news? permanent; break; }
# add more statements like the one above
}
到目前为止,这对我们来说效果很好。不幸的是,我们需要做同样的事情,但是对于可能具有相同 get 参数的不同域。当然,nginx 不允许重复的位置。
location ^~ /content/default.aspx {
if ($args ~ "NewsId=28") { rewrite ^ http://differentexample.org/news? permanent; break; }
}
我尝试了几种不同的解决方案,但都给了我语法错误。我公司里没有人是 nginx 专家了,所以我真的需要一些帮助来解决这个问题。我在位置块中添加了一个if ($host ~ "example.com"),这给了我一个错误。我已经尝试在if ($host ~ "example.com") 块中添加位置块。两次 nginx 都告诉我我不能把它放在那里。
我通常在互联网这个庞大的知识库中找到我的答案,但我似乎正在为此寻找解决方案,而且我们在推出这个客户端之前已经没有时间了。
【问题讨论】:
标签: redirect nginx http-redirect