nginx location regexp for query string

ⅰ亾dé卋堺 提交于 2019-12-10 18:19:45

问题


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.


回答1:


Short answer, try this configuration:

location = / {
    if ( $arg_abc ) {
        rewrite ^ /otherpath/ permanent;
    }
}


来源:https://stackoverflow.com/questions/11305851/nginx-location-regexp-for-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!