【问题标题】:How to rewrite a URL in nginx?如何在 nginx 中重写 URL?
【发布时间】:2019-01-24 09:10:08
【问题描述】:

我正在尝试使用 Nginx 重写 URL,以下是输入和预期输出。

输入:http://localhost/test/studentinfo/DocumentViewer?studentName=ABC&age=25&SchoolName=TREDS&city=HYD

预期输出:http://localhost/student?studentName=ABC&city=HYD

因此,每当我尝试重写 URL 时,我都会在实际替换的 URL 后面得到整个参数 URL,如下所示。

我的重写逻辑:

rewrite ^/test/* /student?studentName=$arg_studentName&city=$arg_city permanent;

但我收到的输出是: http://localhost/student?studentName=ABC&city=HYDstudentName=ABC&age=25&SchoolName=TREDS&city=HYD.

关于我犯了什么错误以及如何实现输出的任何想法。

谢谢!

【问题讨论】:

    标签: nginx url-rewriting nginx-config


    【解决方案1】:

    您缺少尾随 ? 以防止 rewrite 附加原始参数。

    例如:

    rewrite ^/test/ /student?studentName=$arg_studentName&city=$arg_city? permanent;
    

    详情请见this document

    【讨论】:

    • 谢谢理查德!它现在可以正常工作了。
    猜你喜欢
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2023-03-08
    • 2022-01-25
    • 2015-12-20
    • 2019-11-16
    • 1970-01-01
    相关资源
    最近更新 更多