yii2 URL美化

去掉浏览器地址栏中的index.php?r=

目标把链接从:

http://www.digpage.comindex.php?r=post/view&id=100

变成

http://www.digpage.com/post/view/100


在/config/web.php中 ’components‘=>[] 中添加如下代码:

‘urlManager‘ => [

        ‘enablePrettyUrl‘ => true,

        ‘showScriptName‘ => false,//隐藏index.php

         //‘enableStrictParsing‘ => false,

         //‘suffix‘ => ‘.html‘,//后缀,如果设置了此项,那么浏览器地址栏就必须带上.html后缀,否则会报404错误

        ‘rules‘ => [ 7 //‘<controller:\w+>/<action:\w+>‘=>‘<controller>/<action>‘,

        ],

],

如果打开suffix选项,地址栏链接必须带上.html







标签: php yii2
2016.10.25   /   热度:1615   /   分类: php

发表评论:

©地球仪的BLOG  |  Powered by Emlog