【问题标题】:NGINX redirect that matches query string匹配查询字符串的 NGINX 重定向
【发布时间】:2017-03-11 07:13:52
【问题描述】:

我们已从旧系统迁移到新网站。我有很多看起来像这样的旧网址:

/index.php?id=1&groep=26

/site/index.php?id=1&groep=10

新网址的样子:

/medical-information/test-results

没有重写这些 URL 的模式,每个都必须手动完成。

如何使用 NGINX 重定向这些内容?似乎与 index.php 部分之后的查询字符串不匹配。

非常感谢!

【问题讨论】:

    标签: redirect nginx


    【解决方案1】:

    我建议使用带有 $arg_groep 和重写的地图。
    http://nginx.org/en/docs/http/ngx_http_map_module.html
    http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

    您可以在此处找到示例
    https://serverfault.com/questions/609042/nginx-map-directive-for-multiple-variables

    我的建议。

    map $arg_groep $dest {
      26 /medical-information/test-results;
      10 /some/other/URL;
    }
    
    rewrite ^/index.php?id=1&groep=26 $dest permanent;
    

    您将通过此搜索查询找到更多示例。
    https://www.startpage.com/do/dsearch?query=nginx+map+args

    【讨论】:

    • nginx 重写只匹配路径名,?问号,可以匹配url上的任意一个字符。
    猜你喜欢
    • 2019-01-03
    • 2016-07-05
    • 2017-10-04
    • 1970-01-01
    • 2019-05-17
    • 2017-06-02
    • 2019-06-17
    • 2017-04-10
    相关资源
    最近更新 更多