数智学习中心 计科随机库
学习专区 Linux专栏 博客圈 计科之路 登录
nginx下如何l在网站目录的二级目录下url重写的方法

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;

  }

  

}

评论留言

一共0条留言