关于Tp5在nginx环境下重写url规则报404问题

最近忙着搞自己的网站,偶然间发现我切换nginx后,发现之前重写的url全部的都是404错误。一个网站除了首页能开,其他全是404。话不多说,

先来看看两个图。


这是我本地重写之后的url是访问一篇文章


关于Tp5在nginx环境下重写url规则报404问题_第1张图片
在route.php中是这样配置的

按理说这样配置好之后就能够访问了,但是事实打了我的脸:


关于Tp5在nginx环境下重写url规则报404问题_第2张图片


这tm就很有意思了,

然后经过一系列的资料查找,发现必须要nginx先支持pathInfo,我说为啥404原来是这么回事,在经过博主一番激烈的思考的之后,发现以下配置完美的符合了我的需求:


server {

    listen 80 default_server;

    server_name  '域名';

    index index.html index.htm index.php;

    root '地址';

    location / {

    index index.html index.htm index.php;

    #这个if是用来去掉index.php的

    if (!-e $request_filename) {

    rewrite ^(.*)$ /index.php?s=/$1 last; break; } #autoindex on;

    }

    include enable-php.conf;

    location /nginx_status {

            stub_status on;

            access_log off;

    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {

                expires 30d;        

    }

    location ~ .*\.(js|css)?$ {

                expires 12h;

     }

    location ~ /.well-known {

            allow all;

    }

        location ~ /\. {

                deny all;

        }

        location ~ \.php(.*)$ {

                fastcgi_pass 127.0.0.1:9000;

                fastcgi_index index.php;

                #下面两句是给fastcgi权限,可以支持 ?s=/module/controller/action的url访问模式

                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                #下面两句才能真正支持 index.php/index/index/index的pathinfo模式

                fastcgi_param PATH_INFO $fastcgi_path_info;

                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

                include fastcgi_params;

                 }

}

你可能感兴趣的:(关于Tp5在nginx环境下重写url规则报404问题)