URI rewriting based on arguments

Edho Arief me at myconan.net
Sat Nov 8 05:58:28 UTC 2014


On Sat, Nov 8, 2014 at 11:31 AM, B.R. <reallfqq-nginx at yahoo.fr> wrote:
> 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=(?<video>\d+)$ $scheme://$host$uri?vid=$video?
> does not seem to work
>
> 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;
}



More information about the nginx mailing list