- 论坛徽章:
- 0
|
为了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 |
|