1、项目在根目录:
location / {
index index.html index.htm index.php l.php;
autoindex on;
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
2、项目在二级目录: localhost/YII/basic/web
location /YII/basic/web/ {
index index.html index.htm index.php l.php;
autoindex on;
if (!-e $request_filename){
rewrite ^/YII/basic/web/(.*)$ /YII/basic/web/index.php?s=$1 last;
}
}
例如: 以下是一个二级目录系统的测试
#### 伪静态设置
Nginx环境:
if (!-d $request_filename){
set $rule 1$rule;
}
if (!-f $request_filename){
set $rule 2$rule;
}
if ($rule = "21"){
rewrite ^/.*?([^/]*)$ /index.php?$1 last;
}
rewrite ^/db/(?!upload/).*? /[F];
二级目录 study下写成发下样式
location /study/ {
index index.html index.htm index.php l.php;
autoindex on;
if (!-e $request_filename){
rewrite ^/study/(.*)$ /study/index.php?s=$1 last;
}
}