Back

nginx - 去掉url中的某个参数

发布时间: 2019-04-22 07:22:00

参考:https://stackoverflow.com/questions/26384776/nginx-redirect-remove-a-specific-query-parameter-from-url?noredirect=1&lq=1

网上搜了一下,有两个答案靠谱(这个问题的回答比较少,难懂)

    # 删掉某个确认的参数
    if ($request_uri ~ "([^\?]*)\?(.*)unwanted=([^&]*)&?(.*)") {
        set $original_path $1; 
        set $args1 $2; 
        set $unwanted $3; 
        set $args2 $4; 
        set $args ""; 

        rewrite ^ "${original_path}?${args1}${args2}" permanent;
    }

放到 location 段落下面。

如果某个url 中,包含了这个 unwanted 参数,服务器就会返回一个302 跳转请求,然后客户端再次请求,这次发来的就是不包含 unwanted参数的URL了。

Back