Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx location regexp for query string

I want to redirect anything that comes directly to my server with perticuler query string to other location in same domain.

If user comes to

http://www.mydomain.com/?abc=js9sd70s

I want to redirect it to

http://www.mydomain.com/otherpath/?abc=js9sd70s

the query string ?abc=js9sd70s should be the same to new url.

Please suggest nginx config file.

I have tried most of the alternative for below code. by keeping '\' before ? and = sign.

        location ~ /?abc=.* {
                rewrite ^/(.*)$ http://www.mydomain.com/otherpath/$1 permanent;
        }

Please suggest me this location change.

like image 381
Maulik Vora Avatar asked Jul 03 '12 06:07

Maulik Vora


1 Answers

Short answer, try this configuration:

location = / {
    if ( $arg_abc ) {
        rewrite ^ /otherpath/ permanent;
    }
}
like image 75
Sergei Lomakov Avatar answered Sep 20 '22 21:09

Sergei Lomakov