隐藏index.php
创建日期:2015-02-26 16:51

一般规则

location / {
    root /var/www/fbzl.org/;
    index index.html index.htm;

    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }

    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}

Laravel 的 Nginx 重写规则

文档那个上面比较简略,只有:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

您可以加上这些,让你的链接更加优雅

# 去除末尾的斜杠,SEO更加友好
if (!-d $request_filename)
{
    rewrite ^/(.+)/$ /$1 permanent;
}

# 去除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;
}