我有一个访问日志条目,其中有一个“/”,后面紧跟一个“?”
"/?pp=env"
"/?2bhT6ue7ZlYpD0rLyaMsKO4iPy4= <snip>"
"/?2bhUqOt4gXp952HAfQ9G4ggBTNQ= <snip>"
"/?rest_route=/wp/v2/users/"
"/?search==%00{.cookie|UI19tE|value%3dCVE-2014-6287.}"
"/?author=1"
<many more of these>
注意:其中有很多,如果它们都可以与一个正则表达式匹配,那就太好了。
我已经使用了这种技术,效果很好:
location /index.php {
if ($arg_title = Main_Page) {
return 302 $scheme://$host/home;
}
<many more here>
但是当我尝试时:
location ~ ^/\?.* {
rewrite ^ /unknown/ permanent;
}
没有运气。
这有效。
location / {
if ($args ~ ^.+$) { # match an arg with any characters in it
rewrite ^ /unknown/ permanent;
}
...snip...
proxy_pass http://localhost:8000;
}
它仍然匹配正常的 URL 并处理错误的 URL:
myhost/home # pages in my site don't have args
myhost/ # the ending slash navigates to home page
myhost # also navigates to home page
myhost/?crap=x # navigates to /unknown/