您的位置:首页 > 运维架构 > Nginx

Laravel Nginx下配置路由 404 重定向 去index.php的rewrite的规则

2014-11-30 15:30 465 查看
server里加入:

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



配置文件如下:

server
{
listen 80;
#listen [::]:80;
server_name www.xxxxx.com xxxxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.pjcms.com/public;

include other.conf;
#error_page 404 /404.html;

location / { try_files $uri $uri/ /index.php$is_args$query_string; }
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log /home/wwwlogs/www.pjcms.com.log access;
}


或者:

# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: