如何从url nginx中删除两个特定字符



我有此URL xxxxx.com/xxxx/xxxx/xxxxxxxx-xx-2/xxxx,并希望从URL中的第二个参数中删除" -2",并且它以这种方式持续使用xxxxxx。com/xxxx/xx-xx/xxxx," -2"是随机的。我不知道该怎么做:(任何帮助会欣赏它。

我对不良英语的道歉

您应该在下面添加

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

最新更新