免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2832 | 回复: 0

[原创]sina SAE yii 隐藏index.php [复制链接]

论坛徽章:
0
发表于 2012-05-15 20:46 |显示全部楼层
为了url的友好性,yii设计了urlManager ,

这个urlManager是高度可定制的,使用灰常方便呀,

今天跟大家说一下 sina SAE如何隐藏index.php

首先:

在你的根目录下的config.yaml文件中添加下面几句就ok了

# URL重写



handle:

- rewrite: if(!is_dir() && !is_file()) goto "index.php?%{QUERY_STRING}"



这个就相当于apache的htaccess文件的定义:

RewriteEngine on



RewriteCond %{HTTP_HOST} ^eqifa8.com [NC]

RewriteRule ^(.*)$ http://www.eqifa8.com/$1 [L,R=301]



RewriteCond %{SCRIPT_FILENAME} !-f

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1

或者nginx的配置:
  location / {
        index  index.html $yii_bootstrap;
        try_files $uri $uri/ $yii_bootstrap?$args;
    }
接下来在你的config/main.php配置,

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            //'urlSuffix'=>'.html',
            
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),

ok,你已经完成了~
看看我用yii-sae开发的demo吧:http://yiisaedev.sinaapp.com/

原文地址:http://haotushu.sinaapp.com/post-495.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP