NGINX从旧域重定向到新域

0 redirect nginx http-status-code-301

我需要重定向请求像http://domain.com/?part=wordhttp://another_domain/?part=word,"字"可能是不同的

我的nginx配置:

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

重定向不起作用,我做错了什么?

Moh*_*ady 6

而不是指定你想要处理的单词,你可以告诉nginx追加所有的args

server {
  listen 80;
  server_name old.example.com;
  return 301 http://new.example.com$request_uri;
}
Run Code Online (Sandbox Code Playgroud)

更新:
我最近发现$request_uri已经包含查询字符串,因此我$is_args$query_string没有必要的额外部分.我已经更新了上面的部分并删除了额外的查询字符串.