nginx - 如何在 nginx 中重写 URL?
问题描述
我正在尝试使用 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。
关于我犯了什么错误以及如何实现输出的任何想法。
谢谢!
解决方案
您缺少尾随?
以防止rewrite
附加原始参数。
例如:
rewrite ^/test/ /student?studentName=$arg_studentName&city=$arg_city? permanent;
有关详细信息,请参阅此文档。
推荐阅读
- sql - selecting current and previous value from consecutive rows
- python - 为什么不能在 python 中将元组转换为 int?
- groovy - 使用 Groovy (InvokedScriptedProcessor) 将错误的 json 记录写入分离 flowFile
- javascript - 在本机反应中在 textInput 上使用 REGEX
- vue.js - 运行全新的 VUE JS Hello.word 应用程序时出错
- dll - 在 Ada 中动态链接库引入了额外的依赖项
- python - 格式化 json 数组以便在 Python 中为值添加标签
- android - 文本选择取决于手机
- java - 二进制文件问题的数组列表迭代器
- jquery - 使用 OwlBot Dictionary API CORSPolicy 问题