nginx 301使用查询字符串重定向 [英] nginx 301 redirect with query string

查看:89
本文介绍了nginx 301使用查询字符串重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的nginx.conf文件中包含以下内容:

Currently I have something like this in my nginx.conf file:

location ~ /old/page/?$ {
    return 301 /new-page;
}

问题是查询字符串已从/old/page?ref = xx URL中剥离.

The issue is that query strings are being stripped from the /old/page?ref=xx URL.

是否可以使用上面使用的重定向方法来包含查询字符串?

Is it possible to include query strings using the redirect method I'm using above?

推荐答案

?及之后的所有内容都是查询字符串,并且不属于locationrewrite指令中使用的规范化URI的一部分.有关详细信息,请参见本文档.

Anything from the ? and after is the query string and is not part of the normalised URI used in location and rewrite directives. See this document for details.

如果要保留查询字符串,请将其添加到return:

If you want to keep the query string, either add it to the return:

location = /old/page/ {
    return 301 /new/page$is_args$args;
}

或使用rewrite,查询字符串将自动附加,除非添加了?:

Or with rewrite, the query string is automatically appended unless a ? is added:

rewrite ^/old/page/$ /new/page permanent;

有关位置语法,请参见此文档,以及此文档以供返回/重写.

See this document for location syntax, and this document for return/rewrite.

这篇关于nginx 301使用查询字符串重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆