在我的server
指令中,位置配置如下
location ~ \.(html)$ {
expires max;
return 200 "case sensitive match";
}
location ~* \.(html)$ {
expires 10d;
return 200 "case insensitive match";
}
我的期望是,当我加载localhost/somthing.html
时,它应该打印case sensitive match
,当我加载localhost/something.hTML
时,它应该打印case insensitive match
但是,在这两种情况下,都会打印case sensitive match
access.log
中的请求日志为
127.0.0.1 - - [18/Apr/2021:17:56:15 +0530] "GET /something.hTML HTTP/1.1" 200 20 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15"
附件图片,请参阅打印的声明以及设置为MAX
的expires
,以证明case sensitive match
工作正常。这里会出什么问题呢?
发布于 2021-04-19 19:06:47
在文件系统不区分大小写的操作系统(例如Mac和Windows)中,location ~
匹配仍然是不区分大小写的。
要强制使用不区分大小写的模式,您需要使用(?-i)
将其包含在正则表达式本身中。
location ~ "(?-i)\.(html)$" {
...
}
https://stackoverflow.com/questions/67148337
复制相似问题