Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.