【问题标题】:NGINX rewrite parameter to 'pretty' urlNGINX 将参数重写为“漂亮”的 url
【发布时间】:2017-03-01 04:42:41
【问题描述】:

我需要重写用户输入的 URL:

https://local.example.com/mh/526446841/mc90-c

服务器从:

https://local.example.com/mh/526446841/?name=mc90-c

我似乎无法让它工作!我试过了:

rewrite ^/mh/(.*)/(.*)$ /mh/$1/?name=$2? last;

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    在目前的形式中,它鼓励重定向循环,因为目标 URI 仍然匹配 正则表达式

    我能想到三种打破循环的方法:

    1. rewrite 语句移动到server 块中,应该使last 停止所有重写处理。
    2. 在同时处理源和目标的同一 location 块中使用 rewrite 语句意味着可以将 last 更改为 break
    3. 更改正则表达式,使目标URI不再匹配:

      rewrite ^/mh/([^/]+)/(.+)$ /mh/$1/?name=$2? last;
      

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 2020-07-12
      • 2015-11-08
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      相关资源
      最近更新 更多