在Nginx中判断请求参数做跳转

今天有个朋友问我nginx下怎么把请求/abc_123.html的参数非tj=1的请求重定向到/abc_123.html,起初我以为rewrite就可以搞定,后来发现不是那么回事。最后的解决办法是:

if ($args !~ ^($|tj=1$)){
  set $args "";
  rewrite ^/abc_([0-9]+).html /abc_$1.html permanent;
}

rewrite模块只对URI进行处理,并不包含请求参数。

参考:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.