简体   繁体   English

NGINX从旧域重定向到新域

[英]NGINX redirect from old to new domain

I need to redirect requests like http://domain.com/?part=word to http://another_domain/?part=word , 'word' may be different 我需要将http://domain.com/?part=word请求重定向到http://another_domain/?part=word ,“ word”可能有所不同

My nginx configuration: 我的nginx配置:

server {
  listen       80;
  server_name  domain.com www.domain.com;
  rewrite ^/?part=(.*)$ http://another_domain/?part=$1 permanent;
}

redirect does not work, what am I doing wrong? 重定向不起作用,我在做什么错?

instead of specifying what words you want to handle, you can just tell nginx to append all the args 无需指定要处理的单词,只需告诉nginx附加所有args

server {
  listen 80;
  server_name old.example.com;
  return 301 http://new.example.com$request_uri;
}

Update: 更新:
I've recently found out that $request_uri already contains the query string, and thus the extra part that I've had ( $is_args$query_string ) would not be necessary. 我最近发现$request_uri已经包含查询字符串,因此不需要使用多余的部分( $is_args$query_string )。 I've updated the above part and removed the extra query string. 我已经更新了上面的部分,并删除了多余的查询字符串。

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

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