nginx 静态化合集(去掉index.php目录)

访问某域名时,去掉index.php目录时达到效果一样
如:www.test1/index.php/test2跟www.test1/test2效果一致
在vhosts.conf中加重写就可以了
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
 eg:
 
 
server {
listen 80;
server_name dev.pmp.com gohosts.com;
root "D:\project\wanda";
index index.html index.htm index.php;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
如果遇到 修改后无法启动nginx  那就是nginx配置文件中有特殊符号或漏掉符号.  建议用编辑器打开查看修改(!!!!一般用txt文本修改后经常出现特殊符号)
————————————————
#301重定向域名跳转示例 域名先绑定到主机然后修改对应域名去掉以下代码前边的#号即可生效
# if ($Host = 'xxx.com'){
#                 rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
#                 }
 
#discuz3.4伪静态规则示例 请去掉以下代码前边的#号即可生效
# rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
# rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
# rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
# rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
# rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
# rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
# rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
# rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
# rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
# if (!-e $request_filename) {
#   return 404;
# }
 
#phpwind9.0伪静态规则示例 请去掉以下代码前边的#号即可生效
# if (-f $request_filename) {
#           break;
#   }
#    if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") {
#       break;
#   }
#   if (!-e $request_filename) {
#       rewrite . /index.php last;
#   }
 
#WordPress或ThinkPHP伪静态规则示例 请去掉以下代码前边的#号即可生效
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php$1 last;
      break;
  }
#laravel伪静态
 
 location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

  
上一篇:换了XCode版本之后,iOS应用启动时不占满全屏,上下有黑边


下一篇:lnmp 设置ci pathinfo和去掉index.php