Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following Apache rewrite directives:

RewriteCond %{REQUEST_URI} ^/proxy(/|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)uri=(.*?)(&|$) [NC]
RewriteRule .* /api/vs1.0/%2 [NC,L]

And I'm trying out nginx, so trying to move the rewrites over. I came up with...

rewrite ^/proxy(/|$) /api/vs1.0/$2 last;
rewrite (^|&)uri=(.*?)(&|$) /api/vs1.0/$2 last;

Which is probably grossly incorrect. I'm just a mere web developer, so I was wondering if anyone could lend a hand here. I would be much obliged. I see that I am ignoring the query string specification, but I'm thinking that it shouldn't matter. I only have a vague idea of what the original rewrite is accomplishing, so I haven't much hope here in coming up with something decent, despite reading the relevant documentation for both servers.

share|improve this question
up vote 1 down vote accepted

Try this:

location ~* ^/proxy(/|$) {
    if ($args ~* "(^|&)uri=(.*?)(&|$)") {
        set $arg_uri $2;
        rewrite .* /api/vs1.0/$arg_uri last;
  • ~*: for case insensitive matching
  • $args: is the GET parameters in request
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.