0

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.

1

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

Your Answer

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

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