从网址中删除特定的查询参数 [英] Remove a specific query parameter from URL

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

问题描述

我有一个网址,例如:

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

有关更多信息,请参见此文档,以及对于使用if的警告.

See this document for more, and this caution on the use of if.

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

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