【问题标题】:Nginx rewrite - swap path in URLNginx 重写 - URL 中的交换路径
【发布时间】:2018-08-09 08:08:10
【问题描述】:

请帮助我使用 nginx:

网址www.server.com/products/customer/books 应该是www.server.com/customer/products/books

所以我需要将/products//customer/ 交换

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    是的,您可以通过重写来做到这一点。将以下内容添加到您的服务器块:

    rewrite ^/customer/products/(.*)$ /products/customer/$1 last;
    

    或者,如果您有多个 URL(即客户和企业),您可以这样做:

    rewrite ^/(customer|business)/products/(.*)$ /products/$1/$2 last;
    

    【讨论】:

    • 感谢您的回答!但是书籍不是一个类别,有很多类别。我应该在最后使用 $ 吗?所以只有重新排列的客户和产品,但在他们之后……
    • 太棒了!!!非常感谢!最后一个问题 - 如果将来我有客户以外的其他东西,例如业务?我应该使用这个重写 - rewrite ^/(customer|business)/products/(.*)$ /products/(customer|business)/$1 last;rewrite ^/(.*)/products/(.*)$ /products/$1/$2 last; ???
    • 第二个是正确的。我也将它添加到我的答案中。
    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 2019-08-27
    • 1970-01-01
    • 2017-07-05
    • 2022-11-03
    • 2022-11-22
    • 2018-12-12
    • 2023-04-11
    相关资源
    最近更新 更多