博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Yii2.0url美化,去掉r=site/index
阅读量:6422 次
发布时间:2019-06-23

本文共 1506 字,大约阅读时间需要 5 分钟。

hot3.png

1、basic版本:在config/web.中添加

'urlManager' => [    'enablePrettyUrl' => true,  //是否启用美化url     'suffix' =>'.html', //伪静态 后缀用html对seo友好,如果启用了这个配置,  //就必须添加扩展名     'showScriptName' => false,  //是否显示脚本名      'rules' => [    ],],

2、advance版本:在backend/config/main.php中添加以上代码

即可实现 www.test.com/advance/backend/web/index.php/site/login这样的访问方法,再也不用加讨厌的r=site/login了

方法:

Removing index.php from URL in YiiFramework 2.0

To hide the ‘index.php’ and enable the Pretty URL in yiiframework 2.0, this post will help you. For this we have to configure the .htaccess and web.php file.

.htaccess

Please add the following lines in ‘.htaccess’ file inside the ‘web’ directory of yii2.0 application.

1 RewriteEngine on
2 # If a directory or a file exists, use it directly
3 RewriteCond %{REQUEST_FILENAME} !-f
4 RewriteCond %{REQUEST_FILENAME} !-d
5 # Otherwise forward it to index.php
6 RewriteRule . index.php

Configuration of Web.php File

By default ‘config/web.php’ file does not have a option ‘urlManager’. If we want to enable a pretty url, We have to add and configure the ‘urlManager’ in ‘web.php’ file.

To remove the ‘index.php’ from url, we have to the ‘showScriptName’ value as false.
To remove the ‘r’ route variable from url, set the ‘enablePrettyUrl’ value as true.

 

01  

02 'urlManager' => [       
03     'class' => 'yii\web\UrlManager',
04         // Disable index.php
05     'showScriptName' => false,
06         // Disable r= routes
07     'enablePrettyUrl' => true,
08     'rules' => array(
09                  
10             ),
11     ],
   

转载于:https://my.oschina.net/botkenni/blog/842291

你可能感兴趣的文章
是网页变模糊了[JavaScript代码]
查看>>
<Calendar>java时间加减法和格式化输出
查看>>
流行的前端框架整理
查看>>
eclipse插件地址收集
查看>>
git push时出现error: RPC failed; result=22, HTTP code
查看>>
android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架
查看>>
IDEA 新建spring Boot 项目新建后启动失败, 提示Unregistering JMX-exposed beans on shutdown...
查看>>
Tiny4412裸机程序,按键检测
查看>>
[转] JS 返回顶部
查看>>
【30-swift-projects-in-30-days】swift 5 学习 02.Watch'sDemo
查看>>
几个算法题
查看>>
Spring mvc 使用PropertyEditor进行数据转换
查看>>
JavaScript 面向对象学习——1
查看>>
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
查看>>
正确使用 Volatile 变量
查看>>
windows下微信公众号开发(js-sdk)(一)
查看>>
DVB搜索
查看>>
Vuejs——(9)组件——props数据传递
查看>>
EveryChart 搬家了
查看>>
获得magento simple product的custom option信息
查看>>