logo

JTBC5.0新安装首页404内页正常的临时解决方法

2025-02-19 点击 48

说明:请使用nginx搭建环境(不要用Apache搭建)。


在部分环境中,全新安装的JTBC5.0全出现首页404的问题,但内页正常。

通过排查发现,在首页获取的PATH_INFO有问题,需要处理一下。

打开文件\Jtbc\HTTP\Request.php

5.0.0.6及之后版本这样修改

找到代码块

  public function getPathInfo()
  {
    return $this -> server('PATH_INFO') ?? $this -> server('ORIG_PATH_INFO') ?? $this -> server('SCRIPT_NAME');
  }

修改成

  public function getPathInfo()
  {
    $result = $this -> server('PATH_INFO') ?? $this -> server('ORIG_PATH_INFO') ?? $this -> server('SCRIPT_NAME');
    $str = '/';
    if(strpos($result,$str) !== false) return $result;
    else return $str;
  }


5.0.0.5及之前版本这样修改

找到代码块

  public function getPathInfo()
  {
    $result = $this -> server('PATH_INFO');
    if (Validation::isEmpty($result))
    {
      $result = $this -> server('ORIG_PATH_INFO');
    }
    return $result;
  }

修改最后一行代码

  public function getPathInfo()
  {
    $result = $this -> server('PATH_INFO');
    if (Validation::isEmpty($result))
    {
      $result = $this -> server('ORIG_PATH_INFO');
    }
    $str = '/';
    if(strpos($result,$str) !== false) return $result;
    else return $str;
  }



 初步分析是程序缺陷,使用官方提供的伪静态,首页无法正常获取PATH_INFO。


附一些环境与JTBC5的适配情况:

win系统apache集成环境WamPServer默认支持JTBC5;

win系统nginx集成环境phpstudy默认支持JTBC5;

win系统nginx集成环境宝塔面板默认支持JTBC5;

linux系统nginx集成环境宝塔面板默认支持JTBC5;

win系统nginx集成环境phpEnv按本文修改后支持JTBC5;


其它的环境未测试。

0%