关于如何配置Yii的路由的格式, 网上有很多这里不多说, 这里只说Apache下隐藏掉index.php的方法.也是粘贴的前人的.
环境: apache + php
1.开启apache的mod_rewrite模块
编辑 httpd.conf,
去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号
修改<Directory "yourwoot/">...</Directory>中“AllowOverride All”
重启Apache
2.在项目中的/protected/config/main.php中添加代码:'components'=>array(
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false, //隐藏index.php
'rules'=>array(
...略 //自定义url格式
),
),
...
),
3.在与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