yii2 urlmanager的配置

怎样把localhost/index.php?r=user变为localhost/user

1.修改backend/config/main.php,在components数组中增加
  'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName'=> false,
    'rules' => [
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                ['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'news']],
        ],

    ],
2.在backend/web/下增加.htaccess
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php

posted @ 2015-05-29 15:23  yangbanban123  阅读(431)  评论(0编辑  收藏  举报