首页 > 开发 > ThinkPHP > 正文

nginx下使用ThinkPHP框架rewrite以及二级目录问题

2020-10-12 21:05:22
字体:
来源:转载
供稿:网友

nginx版本为1.2.6 thinkphp版本为3.1.2

在nginx下配置thinkphp时,如果需要去除index.php这个默认的路径名,同时修改web服务对应的目录,就需要修改nginx下的default.conf这个里面的配置:

  1. location / { 
  2.         root   /usr/share/nginx/html/xxxxx; 
  3.         index  index.php index.html index.htm; 
  4.         if (!-e $request_filename) 
  5.         { 
  6.           rewrite ^(.*)$ /index.php?s=$1 last; 
  7.         } 

root修改web服务所在文件夹(视个人不同情况),然后抓取获取的url,通过正则抓取所对应的url:

  1. location ~ /.php { 
  2.         set $script $uri
  3.         set $path_info "/"
  4.         if ($uri ~ "^(.+/.php)(/.+)") { 
  5.           set $script $1
  6.           set $path_info $2
  7.         } 
  8.  
  9.         fastcgi_pass 127.0.0.1:9000; 
  10.         #fastcgi_index index.php?IF_REWRITE=1; 
  11.         include fastcgi_params; 
  12.         fastcgi_param PATH_INFO $path_info
  13.         fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/xxxxx$script
  14.         fastcgi_param SCRIPT_NAME $script;  
  15.     } 

最后修改对应的php文件设置path_info修改fastcgi的参数,这样就可以完成对nginx关于thinkphp去掉index.php的问题.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选