问题原文
原帖链接 · NooBskie · CC BY-SA 4.0
I have a couple thousand URL's that look like the following:
https://www.example.com/supplier-shop/u-23452345/s-p/
https://www.example.com/supplier-shop/u-1714128138
https://www.example.com/supplier-shop/u-436877957/s-p
https://www.example.com/supplier-shop/u-32452345
https://www.example.com/supplier-shop/u-2345245664
https://www.example.com/supplier-shop/u-23452345/
This is from my legacy website but our new URL structure looks like the following:
www.example.com/seller/xxxxxxxx
I know how to rewrite single URL's but how would I do a catch all case for all of my id's?
已采纳解答
原帖链接 · Brennen Smith · CC BY-SA 4.0
Here's your answer:
location ~ ^/supplier-shop/(?<id>(.*)) {
rewrite ^ http://$server_name/seller/$id permanent;
}
Works as well for n level directories as well. Example:
> GET /supplier-shop/asdasd/asdasd HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.10.3 (Ubuntu)
< Date: Thu, 28 Jun 2018 00:10:02 GMT
< Content-Type: text/html
< Content-Length: 194
< Connection: keep-alive
< Location: http://www.example.com/seller/asdasd/asdasd
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
