Yii nginx 环境下的路由配置

Nginx配置

在nginx.conf的server {段添加类似如下代码:
Nginx.conf代码:

1
2
3
4
5
location / {
if (!-e $request_filename){#必须有空格
rewrite ^/(.*) /index.php last;
}
}

在Yii的protected/conf/main.php去掉如下的注释

Php代码:

1
2
3
4
5
6
7
8
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'/'=>'/view',
'//'=>'/',
'/'=>'/',
),
),