tags:

views:

19

answers:

1

Hi, I'm new to nginx and I got a rewrite problem here:

I want to permanently redirect http://domain1.com/abc.php to http://domain2.com,

but I want to keep http://domain1.com/abc.php?param=value, I've tried put

rewrite ^/abc\.php$ http://domain2.com last;

which works for http://domain1.com/abc.php, unfortunately it rewrites everything that starts with the '/abc.php', I'm really confused why this is happening, any ideas?

Thanks in advance.

+1  A: 

Nginx rewrites generally don't "see" the query string as part of the URI, which is why your existing rewrite isn't working - to Nginx it's always ^/abc\.php$ whether there's a query string or not.

Instead, I'd try this (adapted from the documentation):

if ($args !~ param=value) {
  rewrite ^/abc\.php$ http://domain2.com permanent;
} 

But be aware that if is evil.

pjmorse