nginx Yii2 伪静态配置


location / {
    # 将所有不是真实文件的路由重定向到 index.php
    try_files $uri $uri/ /index.php$is_args$args;
}

location /backend {
    # 将所有不是真实文件的路由重定向到 index.php
    try_files $uri $uri/ /backend/index.php$is_args$args;
}


下面这个有点复杂:

location / {
    index index.html index.htm index.php;
    autoindex off;
    if (!-e $request_filename) {
        # 地址作为将参数rewrite到index.php上。
        rewrite ^/(.*)$ /index.php/$1 last;
    }
}

location /backend/ {
    index index.html index.htm index.php;
    autoindex off;
    if (!-e $request_filename){
        rewrite ^/backend/(.*)$ /backend/index.php/$1 last;
    }
}