Py学习  »  NGINX

如果url包含“/”,则Nginx重定向?&”

Lorenz • 5 年前 • 786 次点击  

如果url只包含“/”,我需要帮助重定向?&

例子:

https://example.com/?&

重定向到:

https://example.com/

已尝试使用此代码,但无法工作。

location /?& {
  return 301 http://$server_name;
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50450
 
786 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Richard Smith
Reply   •   1 楼
Richard Smith    6 年前

这个 location rewrite 指令对 normalised URI 它不包括查询字符串(来自 ? 继续)。

重定向以结尾的所有uri ?& ,你可以测试 $args 变量。例如:

if ($args = "&") { return 301 $uri; }

或者,只重定向URI /?& ,你可以测试 $request_uri 变量。例如:

if ($request_uri = "/?&") { return 301 /; }