由于某些特殊原因,可能需要将thinkphp6系统运行在域名二级目录中,如通过www.51cto.com/oa访问oa系统,可参考以下操作(仅供参考):

网站目录/www/wwwroot/website  运行目录/subdir/public

Nginx配置root目录:root /www/wwwroot/website/subdir/public;

伪静态:

location ~ .*\.(txt|gif|jpg|jpeg|png|bmp|swf|css|js|ico|doc|xls|xlsx|docx|gif|json)$
{
   #TODO 其它静态文件后缀添加
   rewrite  ^/subdir/(.*)$  /$1  last;   break;
}
location  /subdir/ {
  index index.php;
  if (!-e $request_filename){
    rewrite  ^/subdir/(.*)$  /index.php?s=$1  last;   break;
  }
}


ThinkPHP源码修改以支持二级目录访问

  1. 修改helper.phpurl方法默认domain参数为:true
  2. 修改Url.phpparseDomain方法返回值为:return $scheme . $domain .'/subdir'

动态生成网址如:

Route::buildUrl($avatar)->suffix(false)->domain(true)->build();