问题描述
我有一个网址,例如:
http://www.example.com/something?abc=one&def=two&unwanted=three
我想删除不需要的URL参数,并保持其余URL完好无损,它应该像这样:
I want 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?abc=one&def=two
相对于其他参数,此特定参数可以位于URL中的任何位置.
This specific parameter can be anywhere in the URL with respect to other parameters.
这个问题看起来很简单,但是我尝试了很多次,但最终还是失败了.
The question looks very simple, but I tried many times but failed in the end.
推荐答案
整个查询字符串都出现在$args
变量中或$request_uri
变量的末尾.您将需要构造一个正则表达式来捕获要删除的部分之前和之后的所有内容.
The entire query string is present in the $args
variable or at the end of the $request_uri
variable. You will need to construct a regular expression to capture everything before and after the part you wish to delete.
例如:
if ($request_uri ~ ^(/something\?.*)\bunwanted=[^&]*&?(.*)$ )
{
return 301 $1$2;
}
See this document for more, and this caution on the use of if
.
这篇关于从网址中删除特定的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!