0
我有这个网址xxxxx.com/xxxx/xx-xx-2/xxxx,并希望从网址中的第二个参数中删除“-2”,并保持这种方式xxxxx.com/xxxx/xx-xx/xxxx,“-2”是随机的。我没有想法如何做到这一点:(任何帮助,将不胜感激。如何从网址参数中删除两个特定字符NGINX
我道歉,我的英语不好
我有这个网址xxxxx.com/xxxx/xx-xx-2/xxxx,并希望从网址中的第二个参数中删除“-2”,并保持这种方式xxxxx.com/xxxx/xx-xx/xxxx,“-2”是随机的。我没有想法如何做到这一点:(任何帮助,将不胜感激。如何从网址参数中删除两个特定字符NGINX
我道歉,我的英语不好
您应该添加以下
location ~ /[^/]+/[^/]+-[\d+]/ {
rewrite ^/([^/]+/[^/]+)-[\d+]/(.*) $1/$2 redirect;
}
在URL /part1/part2-number/
的/[^/]+
比赛/part1
,/[^/]+
比赛/part2
和-[\d+]/
匹配-number
,然后你把它改写,删除数字
测试结果:
$ curl -I localhost/tarun/lalwani-2/abc
HTTP/1.1 302 Moved Temporarily
Server: openresty/1.11.2.2
Date: Fri, 06 Oct 2017 11:44:23 GMT
Content-Type: text/html
Content-Length: 167
Location: http://localhost/tarun/lalwani/abc
Connection: keep-alive
$ curl -I localhost/tarun/lalwani-10/abc
HTTP/1.1 302 Moved Temporarily
Server: openresty/1.11.2.2
Date: Fri, 06 Oct 2017 11:44:27 GMT
Content-Type: text/html
Content-Length: 167
Location: http://localhost/tarun/lalwani/abc
Connection: keep-alive