美化URL很重要,URL 看起来顺眼,JJ就不疼。废话不多说,两步搞定。
第一:在配置文件加上 urlManager项,看代码:

 'urlManager'=>[
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules'=>[
	'<controller:(post|comment)>/<id:\d+>/<action:(create|update|delete)>' =>'<controller>/<action>',
	'<controller:(post|comment)>/<id:\d+>' => '<controller>/read',
	'<controller:(post|comment)>s' => '<controller>/list',
	     ],
     ],

第二,在index.php同级目录下新建.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

好了,就是这么轻松。我是YiiSoEasy,胖纸囧是我小弟。

posted on 2017-02-11 13:20  阳光小白  阅读(582)  评论(0编辑  收藏  举报