gpt4 book ai didi

redirect - nginx 301 重定向与查询字符串

转载 作者:行者123 更新时间:2023-12-02 16:40:31 24 4
gpt4 key购买 nike

目前我的 nginx.conf 文件中有这样的内容:

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

问题是查询字符串被从/old/page?ref=xx URL 中删除。

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

最佳答案

? 及其后的任何内容都是查询字符串,而不是 locationrewrite 指令中使用的规范化 URI 的一部分。请参阅this document了解详情。

如果您想保留查询字符串,请将其添加到返回:

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

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

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

参见this document对于位置语法,和 this document用于返回/重写。

关于redirect - nginx 301 重定向与查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40810219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com