yii框架美化url需要在当前文件的config目录下main.php文件中的components的数组中加入这一行配置
'urlManager' => [
'enablePrettyUrl' => true, //美化url==ture
'enableStrictParsing' => false, //不启用严格解析
'showScriptName' => false, //隐藏index.php
'rules' => [
],
],
这是一个解决方案,还有第二个解决方案
一、找到配置文件(ps:advance高级模板)
在工程目录-> backend目录 或 frontend目录 -> config目录 -> main.php文件
-> 在 return 数组下 找到这样一个属性数组开始更改吧
二、目的:我只想去掉浏览器地址栏中的 index.php?r= 这一块。
1、配置文件
'urlManager' => [
'enablePrettyUrl' => true, //true:美化的url,可以去掉?r=
'showScriptName' => false, //false:隐藏index.php
'suffix' => '.html', //后缀,如果设置了此项,那么浏览器地址栏就必须带上.html后缀(加载控制器方法的后面),否则会报404错误
'rules' => [
//设置规则:待续......
],
],
2、后续工作
改完这些还没有结束
我们可以这样访问了 http://localhost/yii_v3/backend/web/index.php/site/login.html
改了以上这些,我发现?r=这块可以用/代替访问了,但是想隐藏掉index.php还是不行。
我们还需在index.php同级的目录下,也就是/web目录下,添加.htaccess文件:
内容如下:
Options +FollowSymLinks IndexIgnore / RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php
也可以是这样(thinkphp中 .htaccess的内容)