简体   繁体   English

Nginx重定向到另一个域并附加新参数

[英]Nginx redirect to another domain and append new parameter

I'm trying to redirect all traffic from my www.old-domain.com to www.new-domain.com , while keeping all path and query parameters in the url, and append a new query parameter such as &from-old=true . 我想所有的交通从我的重定向www.old-domain.comwww.new-domain.com ,同时保持所有的路径和查询参数中的URL,并追加了新的查询参数,如&from-old=true

For example 例如

www.old-domain.com --> www.new-domain.com/?from-old=true
www.old-domain.com/home --> www.new-domain.com/home?from-old=true
www.old-domain.com/item?id=123 --> www.new-domain.com/item?id=123&from-old=true

Please share some thoughts about how I should rewrite/return the url in Nginx to achieve this. 请分享一些有关如何在Nginx中重写/返回url的想法,以实现此目的。

Thanks in advance! 提前致谢!

If you are adding additional arguments to the query string to a URI that may or may not already have a query string, then you should use a rewrite directive, as that will handle the edge conditions correctly. 如果要向查询字符串中的附加字符串添加可能包含或不具有查询字符串的URI,则应使用rewrite指令,因为它将正确处理边缘条件。 See this document for details. 有关详细信息,请参见此文档

For example: 例如:

rewrite ^ $scheme://example.com$uri?from-old=true permanent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM