URI rewriting based on arguments

Hello,

Trying to rewrite an URI based on an argument, I cannot match it
otherwise
than by using rewrite.

The problem is I fail to achieve a working recipe rewriting
example.com/watch?v=123456
to
example.com/watch?vid=123456

rewrite ^/watch?v=(?

rewrite ^/watch? $scheme://$host$uri?vid=blah?
does not either

rewrite ^/watch $scheme://$host$uri?vid=blah?;
works, though it explodes internal rewrites (which is not our concern
here).

The question mark in the first recipe seems to wreak havoc.

  1. Is there any other mean to achieve such a redirection than using
    rewrite?
  2. How to escape a question mark in a rewrite mask, ince escaping
    perl-like does not seem to work?

​Thanks,​

B. R.

On Sat, Nov 8, 2014 at 11:31 AM, B.R. [email protected] wrote:

rewrite ^/watch?v=(?

rewrite ^/watch? $scheme://$host$uri?vid=blah?
does not either

rewrite ^/watch $scheme://$host$uri?vid=blah?;
works, though it explodes internal rewrites (which is not our concern here).

afaict, rewrite doesn’t handle arguments.

if ($arg_v) {
rewrite ^ $uri?vid=$arg_v;
}

That would be a logical conclusion.

However, rewrite
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
documentation is unclear about that. It says ‘If the specified regular
expression matches a request URI’, and nginx has a $request_uri
http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_uri
variable demosntrating what ‘request URI’ means: what the user input
was.
Nowhere it is said that rewrite matches against a normalized URI.

B. R.