Yii在Nginx下的rewrite配置

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

location / {
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}

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

‘urlManager’=>array(
‘urlFormat’=>’path’,
‘rules’=>array(
‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,
‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,
‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,
),
),

刷新测试

若yii在nginx下显示404,请尝试重启nginx,点击查看相关命令

原文链接:,转发请注明来源!

发表评论