|
小猴子先生
博客园 ::首页 ::新随笔 ::联系 ::订阅
::管理 14 Posts ::0 Stories::0 Comments::0 Trackbacks公告
yii框架美化访问路径,去掉index.php/?r=部分一、找到配置文件(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 +FollowSymlinksRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ 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了!Yii2简单地址美化并隐藏index.php 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,页面找不到) posted on 2017-04-11 09:50 小猴子先生 阅读(...) 评论(...) 编辑 收藏刷新评论刷新页面返回顶部 Copyright @小猴子先生
Powered by:.Text and ASP.NET
Theme by: .NET Monster |
|
|