前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Yii2.0url美化,去掉r=site/index

Yii2.0url美化,去掉r=site/index

作者头像
botkenni
发布2022-01-10 10:31:02
5460
发布2022-01-10 10:31:02
举报
文章被收录于专栏:IT码农

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

代码语言:javascript
复制
'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

],

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017/02/20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Removing index.php from URL in YiiFramework 2.0
    • .htaccess
      • Configuration of Web.php File
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档