我有几千个如下所示的 URL:
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/
这是来自我的旧网站,但我们的新 URL 结构如下所示:
www.example.com/seller/xxxxxxxx
id
我知道如何重写单个 URL,但我该如何对所有URL进行全部捕获呢?
答案1
这是你的答案:
location ~ ^/supplier-shop/(?<id>(.*)) {
rewrite ^ http://$server_name/seller/$id permanent;
}
对于级别目录同样适用n
。例如:
> 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
答案2
我想通过像下面这样的重写你可能会实现你想要的
location ~ ^/supplier-shop/(.+) {
rewrite ^ http://$server_name/seller/$1 permanent;
}
猜猜http://$服务器名称可以省略,但老实说,我现在没有 nginx 来尝试我建议的操作,所以最好尝试一下并查看结果。
基本上,它所做的就是用“卖方”取代“供应商商店”,并将所有后续内容付诸实施。
如果这不是你想要实现的,请告诉我们