且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从网址中删除特定的查询参数

更新时间:2023-11-27 16:10:04

整个查询字符串都出现在$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.