加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx重写地址不会自动添加参数

发布时间:2020-12-13 21:17:31 所属栏目:Nginx 来源:网络整理
导读:原始请求地址: www.example.com/index.php?r=mobile/receive/index 重写的请求地址: www.example2.com/newindex.php?r=mobile2/receive2/index2 这是我自己的配置: if ($args ~* "^r=mobile/receive/index") { rewrite ^ "http://www.example2.com/newind

原始请求地址:

www.example.com/index.php?r=mobile/receive/index

重写的请求地址:

www.example2.com/newindex.php?r=mobile2/receive2/index2

这是我自己的配置:

if ($args ~* "^r=mobile/receive/index") {
    rewrite ^ "http://www.example2.com/newindex.php?r=mobile2/receive2/index2";
}

但重写地址的结尾是这样的:

http://www.example2.com/index.php?r=mobile2/receive2/index2&r=mobile/receive/index

你看到我的问题了吗?重写的地址会自动添加,但这不是我想要的.相同的参数键将导致后盖正面.

最佳答案
为了防止将原始查询字符串附加到目标URL,您需要在重写的URL末尾包含一个附加问号(?).例如:

rewrite ^ http://www.example2.com/newindex.php?r=mobile2/receive2/index2?;

参考:
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读