regex - nginx 根据 uri 中的参数 id 重定向
问题描述
需要根据 personId uri 参数进行重定向。
将https://server.com/de/prints/?personId=1重定向到https://anotherserver.com/dir1/dir2/dir3/dir4/dir5/the-result?statusId=1&personId=1
需要对每个 personId 值执行此操作,所以基本上如果请求是:https://server.com/de/prints/?personId=2 将其重定向到 https://anotherserver.com/dir1/dir2/dir3/dir4/ dir5/the-result?statusId=1&personId=2
我尝试了以下方法,但它不起作用:
location ~* ^/de/prints? {
if ($args ~* "personId=*") {
rewrite ^.*$ https://anotherserver.com/dir1/dir2/dir3/dir4/dir5/the-result?statusId=1&personId=$1 redirect;
}
}
解决方案
为了$1
在您的 URL 中使用,您需要使用括号(捕获组)捕获原始 URL 中人员的 ID。
类似的东西.*[&?]personId=([0-9]+)
而不是^.*$
推荐阅读
- firebase - 颤动的ios没有与firebase连接
- scp - 我们可以在windows中使用scp命令列出目录的内容并按修改时间排序吗
- java - 为什么pdf只包含一个字段大约是500Kb
- python - 使用 Python 清除验证码图像的线条噪声
- html - html 对象能否将自身作为参数传递给 JS 函数
- c++ - 为什么通过 BLE 的串行通信在第一次运行代码时失败,但在连续运行时工作正常?
- javascript - 倒数计时器完成后如何自动播放音频?
- php - Symfony 3 - 如何通过 bcrypt 加密的密码对用户进行身份验证?
- c - 如何创建一个从 99% 倒计时到 0% 的计时器,每秒减少 1%
- python - 从 cassandra 获取所有数据