码迷,mamicode.com
首页 > Web开发 > 详细

yii去除index.php的入口脚本显示为seo友好的url

时间:2014-09-15 22:36:59      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   使用   ar   strong   

1.去除入口脚本需要在重写url,如果你的webserver软件时Apache的话,必须配置httpd.conf,搜索“LoadModule rewrite_module modules/mod_rewrite.so”,然后去掉此行前面的“#”[ps:注释符号]:

 bubuko.com,布布扣

2.在yii的web应用程序主配置文件main.php[path\to\protected\config\main.php],使用urlManager增加一个数组配置选项‘showScriptName‘=>false:

1 ‘urlManager‘=>array(
2             ‘urlFormat‘=>‘path‘,
3             ‘showScriptName‘=>false,//去除入口脚本index.php的显示
4             ‘rules‘=>array(
5                 ‘post/<id:\d+>/<title:.*?>‘=>‘post/view‘,
6                 ‘posts/<tag:.*?>‘=>‘post/index‘,
7                 ‘<controller:\w+>/<action:\w+>‘=>‘<controller>/<action>‘,
8             ),
9         ),

3.从项目的其它路径中复制一份.htaccess文件到与入口脚本index.php相同层次的路径下,用以下代码覆盖其中的内容:

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

关于apache重写规则的定义,请见:http://httpd.apache.org/docs/2.2/en/mod/mod_rewrite.html#rewriterule 以及http://www.maxi-pedia.com/FollowSymLinks

另外,如果你不知道如何在windows下创建没有文件名的文件可以使用如下方式创建到一个路径下:

bubuko.com,布布扣

yii去除index.php的入口脚本显示为seo友好的url

标签:style   blog   http   color   io   os   使用   ar   strong   

原文地址:http://www.cnblogs.com/bszm/p/3973666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!