在Nginx中,如何匹配整个URL和查询字符串以及如何重定向到URL和查询字符串
我已经搜索了一段时间,尝试变通方法,并且没有提出任何有用的信息.
I have been searching for a while now, trying work arounds and haven't come up with anything useful.
我有一个(大)网站迁移中的URL列表,需要匹配整个URL +查询字符串并重定向到另一个URL.
I have a (large) list of URL's from an site migration and need to match the entire URL + Query String and redirect to another URL.
据我所知,以下仅匹配/mens
,而不匹配其余的查询字符串.
As far as I can see the following only matches /mens
, but not the rest of the query string.
rewrite "^/mens?brand%5B%5D=27§ion%5B%5D=5&price-min=0&price-max=2000&sort=newest" "/t/gender/men" permanent;
重要的原因是我有一堆类似的URL,但查询字符串略有不同,需要重定向,类似于下面的内容,但实际上可以工作....:-/
The reason it's important is that I have a bunch of similar URL's with slightly different Query Strings, which need to be redirected, similar to below, but actually work.... :-/
rewrite "^/mens/shop?q=road+map+polo" "/t/category/golf-knits" permanent;
rewrite "^/mens/shop?q=six+pocket+pant" "/t/category/golf-pants" permanent;
#etc... ad noiseam
预先感谢, 保罗.
$request_uri
变量包含整个URL.您可以使用map
将其转换为重定向.
The $request_uri
variable contains the entire URL. You could use a map
to translate it into a redirection.
map $request_uri $target {
~*^/mens/shop\?q=road\+map\+polo /t/category/golf-knits;
~*^/mens/shop\?q=six\+pocket\+pant /t/category/golf-pants;
}
server {
...
if ($target) { return 301 $target; }
...
}
有关详细信息,请参见本文档.
See this document for details.