0

I need to redirect requests like http://domain.com/?part=word to http://another_domain/?part=word, 'word' may be different

My nginx configuration:

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?

1 Answer 1

8

instead of specifying what words you want to handle, you can just tell nginx to append all the 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. I've updated the above part and removed the extra query string.

Sign up to request clarification or add additional context in comments.

1 Comment

See Nginx documentation for this use case: nginx.org/en/docs/http/converting_rewrite_rules.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.