Laravel的Nginx重写规则--让路由支持末尾加斜线
默认laravel路由末尾不能加/,如果加了斜线会报404
要想支持url末尾的斜线需要在public/index.php加入如下代码:
$_SERVER['REQUEST_URI'] = trim($_SERVER['REQUEST_URI'], '/');
# 去除index action
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# 根据laravel规则进行url重写
if (!-e $request_filename)
{
rewrite ^/(.*)(/)?$ /index.php?/$1 last;
break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
posted on 2017-06-06 10:52 dongruiha 阅读(2518) 评论(0) 编辑 收藏 举报