返回列表 發帖

[PHP] CodeIgniter 的 Router 在 WebHostingPad 主機上遇到的問題

今天在 WebHostingPad 的虛擬主機上發現 CodeIgniter 在 URL Rewrite 後,無法抓到正確的 Controller

經過檢查後發現,原來有些主機上的環境變數名稱不太一樣,原本應該是透過 $_SERVER['PATH_INFO'] 來取得網址的路徑,但是這台主機上要用 $_SERVER['ORIG_PATH_INFO'] 來取。再加上原本 CodeIgniter 程式內的處理方式也不能運作,所以就改了一下 code:

/system/libraries/URI.php Line 91:
// No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
if (trim($path, '/') != '' AND $path != "/".SELF)
{
  // remove path and script information so we have good URI data
  $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);
  return;
}
改成了這樣:
// No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
$path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
if (trim($path, '/') != '' AND $path != "/".SELF)
{
  // remove path and script information so we have good URI data
  // $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);
  $this->uri_string = $path;
  return;
}
PS. CodeIgniter 版本是 1.6.3
To infinity and beyond!

返回列表 回復 發帖