xiaobai 2015-06-08 17:50:03 4866次浏览 2条评论 1 1 0

1、首先需要把apache或者nginx的rewrite模块开启
2、打开config/web.php文件,在components里添加如下代码:

'urlManager' => [
    //'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules'=>[
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ],
],

3、添加.htaccess文件,内容如下:

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
觉得很赞
您需要登录后才可以评论。登录 | 立即注册