目标:把这个url重写成下面那种
http://localhost/yii/index.php?r=site/login
http://localhost/yii/site/login
一、确定你的apache有rewrite模块,可以通过phpinfo()来查看。
没有怎么办?自己百度
二、编辑yii的配置文件 main.php
找到
1 2 3 4 5 6 7 8 9 10 |
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'
|
把注释去掉
现在应该可以看到效果了,但是还是有写瑕疵,我们要吧入口文件index.php去掉
三、在网站根目录新建一个文件.htaccess
1 2 3 4 5 6 7 8 9 |
<IfModule rewrite_module> Options +FollowSymLinks IndexIgnore */* RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php |
ok虽然去掉index.php也不报错,但是默认路径还是带了index.php
最后一步,更改配置文件main.php
找到
1 |
'urlFormat'=>'path', |
在它下面增加
1 |
'showScriptName'=>false, |
大功告成!!