Nginx 重定向 - 从 URL 中删除特定的查询参数 [英] Nginx Redirect - Remove a specific query parameter from URL

查看:66
本文介绍了Nginx 重定向 - 从 URL 中删除特定的查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 URL,例如:

Let's say I have a URL such as:

http://www.example.com/something.html?abc=one&def=two&unwanted=three

我想删除 URL 参数 unwanted 并保留 URL 的其余部分,它应该如下所示:

I would like to remove the URL parameter unwanted and keep the rest of the URL in tact and it should look like:

http://www.example.com/something.html?abc=one&def=two

相对于其他参数,此特定参数可以位于 URL 中的任何位置.无论如何,重定向都应该有效.

This specific parameter can be anywhere in the URL with respect to other parameters. The redirect should work regardless.

这能实现吗?

推荐答案

你可以这样实现

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

这篇关于Nginx 重定向 - 从 URL 中删除特定的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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