yii2 urlmanager的配置

时间:2015-05-29 17:36:16   收藏:0   阅读:2274

怎样把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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!