112 nginx去掉index.php 只需2个步骤

为了使URL更简洁优雅些,我们可以通过Nginx的rewrite规则把index.php去掉。

Thinkphp 框架如果有数据分页的页面需要修改入口文件

//nginx环境下防止U方法输出错误
define('__APP__', '');  //在入口文件index.php中添加这一句

第一步:要编辑子站的配置文件

vi  /usr/local/nginx/conf/vhost/子站.conf

把 include enable-php.conf   注释掉这行!(或者直接dd删除)

然后在下面新曾一行  添加 

include enable-php-pathinfo.conf;   #注意后面必须带分号

第二步:

cd /usr/local/nginx/conf/vhost/子站.conf 

vi 子站.conf           在你的虚拟主机配置文件server段里添加以下内容:

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

重启nginx!!

更多内容请关注微信订阅号:phpstory

猜你喜欢

转载自blog.csdn.net/phpstory/article/details/81701848
112
今日推荐