加入收藏 | 设为首页 | 会员中心 | 我要投稿 台州站长网 (https://www.0576zz.cn/)- 边缘计算、中间件、数据处理、数据分析、智能存储!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2021-02-20 19:43:01 所属栏目: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) { rewri

原始请求地址:

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

(编辑:台州站长网)

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

    推荐文章
      热点阅读