一、找到配置文件(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的内容)
 
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
 
3、报错信息
没有.htaccess 文件回报这样的错误
 
The requested URL /yii_v3/backend/web/site/login.html was not found on this server.
 
4、测试成功
最后测试OK了!
 
5、示例解释
访问路径示例:http://localhost/yii_v3/backend/web/site/login.html
 
解释:
localhost:本地服务器地址
yii_v3:工程目录
backend:工程下的后台目录
web:backend下的web目录
site:控制器
login:控制器方法
.html:后缀
 
6、小小提醒
上面的步骤都完成,我们可以美化的输入地址访问了,心情很美丽
 
不过还可以这样访问是没有问题的注意红色标记的位置
①http://localhost/yii_v3/backend/web/index.php/site/login.html ( 此处的index.php会保留,不影响访问 )
 
②http://localhost/yii_v3/backend/web/?r=site/login.html ( 访问以后,框架会自动抹掉 ?r= ,可以继续访问)
 
③http://localhost/yii_v3/backend/web/index.php/?r=site/login.html ( 访问以后,框架会自动抹掉 ?r= ,但是index.php会保留 , 可以继续访问)
 
④http://localhost/yii_v3/backend/web/site/login (注意这里没有 .html 后缀,报错 not found 404,页面找不到)
 

最新文章

  1. [Unity3D]自制UnityForAndroid二维码扫描插件
  2. jQuery简单入门
  3. AndroidAnnotations简单示例
  4. SQL总结(三)其他查询
  5. 【WCF--初入江湖】05 WCF异步编程
  6. C++带参数默认值的函数
  7. UC浏览器插件开发
  8. C# 语言规范_版本5.0 (第3章 基本概念)
  9. Linux下检测进程是否存在
  10. 【activity任务栈】浅析
  11. Centos7开机启动自己的脚本的方法
  12. 【转】Android hdpi ldpi mdpi xhdpi xxhdpi适配详解
  13. Codeforces 420D Cup Trick 平衡树
  14. WebService相关
  15. got positional argument after named arguments.原因
  16. [HAOI2006]l旅行
  17. [Java学习]面向对象-package;内部类;UML图表示六种关系
  18. (转)AssetBundle系列——共享资源打包/依赖资源打包
  19. 面试6 在c#中如何声明一个类不能被继承
  20. VS2005自定义ActiveX控件在asp.net中应用方法

热门文章

  1. php实现的三个常用加密解密功能函数示例
  2. Python编写一个程序求2的次方
  3. keil swd设置下载stm32f103c8t6.
  4. 笔记-算法-KMP算法
  5. Diycode开源项目 NotificationActivity
  6. 03017_ajax
  7. SXCPC2018 nucoj2004 国王的怪癖
  8. loj2052 「HNOI2016」矿区
  9. WampServer配置说明
  10. linux简单授权