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

来源:互联网 发布:软件项目管理方法 编辑:程序博客网 时间:2024/05/29 17:23

为了使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;
     }
}


完成!


结果:http://localhost/Home/Index/mod   访问正常!