redirect - Nginx 重定向 - 从 URL 中删除特定的查询参数

标签 redirect nginx

假设我有一个 URL,例如:

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

我想删除 URL 参数 unwanted并保持 URL 的其余部分完整,它应该如下所示:
http://www.example.com/something.html?abc=one&def=two

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

这能实现吗?

最佳答案

你可以通过这种方式实现

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

关于redirect - Nginx 重定向 - 从 URL 中删除特定的查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26384776/

相关文章:

node.js - Nginx 配置错误反向代理在启动 nginx 时显示 "Welcome to nginx"

c# - 将 printf C++ 控制台输出重定向到 C#

php - 重定向到登录页面

javascript - GAS(谷歌应用程序脚本)/Google Drive API : Retrieving a redirected URL from pre redirect link

php - 如何使用 PHP 创建错误 404 页面?

Nginx不监听其他端口,只监听80端口

nginx - 如何在 Docker 镜像中使用 Nginx 连接到我的应用程序?

php - window.location (JS) vs header() (PHP) 用于重定向

php - 重新启动 php-fpm 时如何避免出现 502 网关错误?

ssl - 允许每个 ssl_verify 的 Nginx 问题,忽略的位置不起作用