How to remove hypen (-) using nginx rewrite rule?

user3382916 asked:

I am using this rewrite rule to redirect

example.com/a-b-c?id=learn-more —-> http://example.com/abc?id=learnmore

rewrite ^/a-b-c?id=learn-More http://example.com/abc?id=learnMore permanent

But its not working !! It is redirecting to

example.com/abc?id=learn-more (learn-more is not converted to learnmore).

How to achieve this?

My answer:


If you just have one (or maybe a few) of these to match exactly, then you can check the argument explicitly.

if ($arg_id = "learn-More"} {
    return 301 $scheme://$http_host$uri?id=learnMore
}

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.