本文为笔者学习笔记,参考《Nginx高性能Web服务器详解》
自动为请求的URL末尾添加“/”
location ^~ /vote {
if (-d $request_filename) {
rewrite ^/(.*)([^/])$ https://$server_name/$1$2/ permanet;
}
}
参数解释:
^~:用于标准uri前,要求Nginx服务器找到标识uri和请求字符串匹配度最高的location后,立即使用location请求处理,而不再使用location块中的正则uri和请求字符串做匹配;
-d ¥request_filename:标识如果是目录就返回true;
^/(.*)([^/])$ https://$server_name/$1$2/ :正则表达式,$1为uri开始到最后一个字符(不包含最后一个字符),$2表示最后一个字符;
示例:http://www.baidu.com/vote 会被重写为:https://www.baidu.com/vote/,其中$1为vot,$2为e;