假设我有一个 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;
}