• I'm trying to accomplish the following: listen to all incoming requests, and if a certain query parameter exists, redirect to another location with that query parameter set.

My problem is, that I cannot avoid triggering redirect loops, because ngnix keeps hitting the query parameter rule and thus redirecting again.


# the redirect location
location /redirect {
    # do nothing, this should be accepted
# listen for myparam query parameter and redirect to /redirect
location / {
   if($arg_myparam) {
      return http://mysite/redirect/?myparam=$myparam;

As you can see, I'm trying to direct all page requests containing "myparam" query parameter to the /redirect route.

I can see why this triggers a loop, but I cannot for the love of God see how I can avoid it... any help is greatly appreciated


  • Put the If statement inside a block location / – Drifter104 Jan 25 '16 at 12:53
  • Hi @Drifter104, I've tried that as well.. will try again and if that helps, will modify the question.. thanks – Spock Jan 25 '16 at 12:57
  • Can you include an example of an original url? – Drifter104 Jan 25 '16 at 13:03
  • would be something like mysite.mydomain.com/whatever/girlfriend?myparam=1111111 – Spock Jan 25 '16 at 13:36
  • I've tried to put the listening directive inside a location block, but this still triggers a loop.. ideally the first /redirect location should be caught and then nothing else happen.. but it seems like the location / is still processed somehow.hmmm – Spock Jan 25 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.