yii2 url 美化

1.在main.php文件中开启 urlManager组件

  'urlManager' => [
            'enablePrettyUrl' => true,
            // 'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+\-\w+|\w+>/<action:\w+\-\w+|\w+>'=>'<controller>/<action>',
                '<module:\w+\-\w+|\w+>/<controller:\w+\-\w+|\w+>/<action:\w+\-\w+|\w+>'=>'<module>/<controller>/<action>',
                '/'=>'user/login',
            ],

        ],

2.在backend/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

  

 

posted on 2018-12-11 10:07  running-fly  阅读(810)  评论(0编辑  收藏  举报

导航