让Nginx 的URL目录自动加斜线”/”

No replies
philip
philip's picture
User offline. Last seen 1 day 7 hours ago. Offline
Joined: 04/11/2010
Points: 14961
Groups: 324

默认配置当你访问http://abc.example.com/dir 时不会加”/”

常见做法

if (-d $request_filename){
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}

更佳的替代方法

optimize_server_names off;#优化服务器名称:关
server_name_in_redirect off;#服务器名称重定向:关