2023-10-20

Codeigniter 如何解決本機 IP 無法連線網站的問題

這幾天客戶的系統搬回內網,不再提供對外網址連線。

結果反而打本機 IP,有前端畫面顯示不完全,研判是 CSS and JS 無法載入的問題。網站是用 Codeigniter 開發的,開始查找原因,可能是網址的問題,試著用下述方法,果然有用!

解決方式

把 base_url 改成動態內容, 並兼容 https and http, 網頁就能正常顯示了!

  1. 在網站目錄找到 [application] -> [config] -> [config.php]
  2. 設定 $config['base_url'] 的內容如下:
// 如果系統支援 https 協定,就開啟 https, 不然就用 http
$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
// 支援網址或 IP 的 protocol 連線網站
$config['base_url'] = $protocol.'://'.$_SERVER['HTTP_HOST'].'/site folder name/';

請我喝杯咖啡吧 ^^
No active "bsf-sb-post-end" sidebar

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

PeiYing Tsai
author
愛藝術,喜歡以科技解決問題的數位產品設計師。 堅持信念,任何困難事,必有搞定的一天,Just try it! 隨手紀錄日常學習到的知識心得,希望對妳/你有幫助。
coffee-cup linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram