yii2 如何使用 PATH_INFO 模式 并去掉 index.php

来源:互联网 发布:js获取一个对象的长度 编辑:程序博客网 时间:2024/06/06 18:34

众所周知yii2的的初始URL方式是 http://localhost/yii2/web/index.php/?r=hello/index

而我们一般习惯使用的URL方式是http://localhost/yii2/web/index.php/hello/index

所以一般初学者上手yii2的第一件事情就是 重写URL

重写URL非常简单打开config下下的web.php‘components’ 配置项里加入下面的代码

 'urlManager' => [                //设置pathinfo模式            'enablePrettyUrl' => true,            'showScriptName' => false,            'rules' => [            ],        ],

这里写图片描述

就可以改成PATH_INFO模式了

至于怎么去掉index.php 也非常容易

如图在web目录下加入 .htasccess 即可

这里写图片描述

.htasccess 文件的内容如下

<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

因为我下载的集成环境wamp64 比较新 所以在win10 下 很多参数 不需要 修改 如果 使用了我的方法还是不行 最简单的方法就是下载一个wamp64 当然继续百度也是一个好选择

原创粉丝点击