Nginx多重写规则

时间:2015-11-26 09:10:11

标签: nginx rewrite

您好我想从桌面版网站重定向我的移动用户。移动服务器基于nginx,我正在添加重写规则:我必须添加50条规则,不知道任何捷径..但问题是规则不适用于后缀。例如,在我的桌面网站上我有

http://www.example.com/watch/tv-commercial/aci-aerosol-hd/ http://www.example.com/category/tv-commercial/

http://www.example.com/category/music-video/

http://www.example.com/watch/music-video/aji-e-boshonte/

我想重定向

http://www.example.com/watch/tv-commercial/

此群组为http://m.example.com/funny-clips

和这个小组

http://www.example.com/category/music-video/

http://m.bongobd.com/full-movie-natok

如果我写

location = /watch/tv-commercial/ {
   return 301 /funny-clips;
}

它有效,但如果它有" aji-e-boshonte"

它不起作用。

任何人都可以帮忙吗?我也有多个传入规则来重定向一条路由。例如/ tv / movie / comedy(with slug)to / funny-clips我需要每次写规则吗?

1 个答案:

答案 0 :(得分:1)

location =寻找完全匹配。您需要使用前缀位置或正则表达式位置。例如,要将/watch/tv-commercial/path/to/file重写为http://m.example.com/funny-clips/path/to/file,您可以使用:

location ~* ^/watch/tv-commercial/(.*)$ {
  return $scheme://m.example.com/funny-clips/$1$is_args$query_string;
}

有关详细信息,请参阅this documentthis document