yii的URL美化

ULR美化需要nginx的配合完成的。
本人是使用阿里云的lnmp构建。故以其为例,记录如下:
1.nginx的配置如下:
首先是rewrite规则,在/alidata/server/nginx/conf/rewrite目录下增加aixuefo.conf文件,其内容如下:

location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

接着是主站的配置,在/alidata/server/nginx/conf/vhosts目录下新增aixuefo.conf文件,其内容如下:
server {
listen 80;
server_name www.aixuefo.com aixuefo.com;
index index.html index.htm index.php;
root /alidata/www/aixuefo;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/alidata/server/php/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9132;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
#伪静态规则
include /alidata/server/nginx/conf/rewrite/aixuefo.conf;
access_log /alidata/log/nginx/access/aixuefo.log;
}

然后是yii的组件配置:如下
‘urlManager’=>[
‘enablePrettyUrl’=>true,
‘rules’=>[
// ‘dashboard’ => ‘site/index’,
//
// ‘POST s’ => ‘/create’,
// ‘s’ => ‘/index’,
//
// ‘PUT /‘ => ‘/update’,
// ‘DELETE /‘ => ‘/delete’,
// ‘/‘ => ‘/view’,
// ‘//‘ => ‘/‘,
‘posts’ => ‘post/default/list’, 只测试这个小小例子
],

],