用于查询字符串的nginx位置正则表达式 [英] nginx location regexp for query string

查看:148
本文介绍了用于查询字符串的nginx位置正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将使用perticuler查询字符串直接发送到服务器的所有内容重定向到同一域中的其他位置.

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

如果用户访问

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

我想将其重定向到

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

查询字符串?abc=js9sd70s应该与新网址相同.

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

请建议使用nginx配置文件.

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;
        }

请建议我更改位置.

推荐答案

简短答案,请尝试以下配置:

Short answer, try this configuration:

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

这篇关于用于查询字符串的nginx位置正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆