nginx配置后只有根目录首页index.php能访问,其他页面404

只有首页面根目录可以访问,其他页面地址都是404 not found。网上有很多介绍用url重定向,url重写都试了无效,要不就是重定向过多。其实解决方法很简单:

以phpstudy2016环境组合包为例:

1、打开vhosts.conf;

2、找到对应的域名;

  listen       80;
        server_name  www.xuduowei.com xuduowei.com;
        root   "E:/phpStudy/WWW/xuduowei/public";
        location / {
            #index  index.html index.htm index.php;
            #autoindex  on;
              try_files $uri $uri/ /index.php?$query_string;
                if (!-e $request_filename){  
                   rewrite ^/(.*) /index.php last;  
               }
        }

注意实际增加:

   try_files $uri $uri/ /index.php?$query_string;
                if (!-e $request_filename){  
                   rewrite ^/(.*) /index.php last;  
               }

注意:若是nginx服务器,直接增加如下配置:

    location / {
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }

提示:若你的vps是虚拟机,要找准虚拟机下对应的配置项!

徐老师项目亲测有效!想学习php开发的,可以联系我。微信:weilanweb 或者15309695130


关注公众号,了解更多it技术(it问答网

发表评论

电子邮件地址不会被公开。