Yii学习(9)----糊里糊涂URL重定义

来源:互联网 发布:手机淘宝包邮 编辑:程序博客网 时间:2024/06/02 23:35

去除index.php?

在apache服务器下面:

开启mod_rewrite模块 =>这个百度一下

在项目入口文件(index.php)同级下加入.htaccess文件,写入:

<IfModule rewrite_module>    Options +FollowSymLinks    IndexIgnore */*    RewriteEngine On    RewriteCond %{REQUEST_FILENAME} !-f    RewriteCond %{REQUEST_FILENAME} !-d    RewriteRule . index.php</IfModule>

在主配置文件(config/main.php)的components-->urlManager中加入:

'showScriptName'=>false,

这时,index.php就可以去除了。

在rules可以自定义自己的url格式:这里将urlrules.php引入到rules=>include(urlrules.php),中

return array('<controller:\w+>/<id:\d+>'=>'<controller>/view','<controller:\w+>/v/<id:\d+>'=>'<controller>/view',//video/v和match/v定制'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>','<controller:\w+>/<action:\w+>_<id:\d+>'=>'<controller>/<action>',//为视频分类定制的URL,文章分类定制URL'<controller:\w+>/<action:\w+>_<id:\d+>_<page:\d+>'=>'<controller>/<action>',//为视频分类定制的URL'<controller:\w+>/<action:\w+>'=>'<controller>/<action>','video//'=>'video/index/','/city-<areaname_e:\w+>/'=>'diaodian/area/',//定制'/city-<areaname_e:\w+>/diaodian/'=>'area/index/',//定制);






1 0