先来看看个rewrite的配置
rewrite ^/test/para(-a(\d+))?(-b(\d+))?(-c(\d+))?(-d(\d+))?(-e(\d+))?(-f(\d+))?(-g(\d+))?\.html$ /web/target.jsp?a=$2&b=$4&c=$6&d=$8&e=$10&f=$12&g=$14;请求URI: /zhuangxiu/q-a1-b2-c3-d4-e5-f6-p7.html提问:target.jsp里通过request.getQueryString()获取到的是什么?理论及期望:a=1&b=2&c=3&d=4&e=5&f=6&g=7实际:a=1&b=2&c=3&d=4&e=-a10&f=-a12&g=-a14解决方案:
rewrite ^/test/para(-a(\d+))?(-b(\d+))?(-c(\d+))?(-d(\d+))?(-e(?<ys>\d+))?(-f(?<yt>\d+))?(-p(?<pg>\d+))?\.html$
/web/target.jsp?a=$2&b=$4&c=$6&d=$8&e=$ys&f=$yt&g=$pg; 这个是由于nginx是不支持rewrite参数超过10个的
如果了解named capturing group的同学就很清楚了,后面再简单介绍下named capturing group。