Nginx重定向-从URL中删除特定的查询参数 [英] Nginx Redirect - Remove a specific query parameter from URL
本文介绍了Nginx重定向-从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.
这可以实现吗?
推荐答案
您可以通过这种方式实现
You can achieve that this way
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屋!
查看全文