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

文章来自:http://www.cnblogs.com/yangbanban/p/4538597.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3