nginx 301使用查询字符串重定向 [英] nginx 301 redirect with query string
问题描述
目前,我的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?
推荐答案
?
及之后的所有内容都是查询字符串,并且不属于location
和rewrite
指令中使用的规范化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屋!