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

发布时间:2026-04-19 03:06

R语言统计分析:使用r-project.org的文档和包 #生活技巧# #工作学习技巧# #编程学习资源#

最新推荐文章于 2026-04-16 18:05:07 发布

转载 于 2017-02-20 17:07:00 发布 · 497 阅读

· 0

· 0 ·

CC 4.0 BY-SA版权

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

'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.

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

网址:Yii2.0url美化,去掉r=site/index https://www.yuejiaxmz.com/news/view/1452237

相关内容

Site Index
用R进行文件系统管理
thinkphp url去掉index.php,thinkphp 去掉URL 里面的index.php(?s=)
Your access to this site has been limited by the site owner
list index out of range
Free dating site for singles in UK
pleasant to get home
Online Dating Site
index match函数的使用方法
Guangzhou Doctor Gang Home Products Co., Ltd.

随便看看