簡體   English   中英

代碼點火器站點的基本 url 不起作用

[英]base url for code igniter site not working

CodeIgniter 的新手,弄濕了我的腳。

較舊的(5 歲?)CI 網站。 將其移至 A2 的新虛擬主機並進行了設置。

主頁出現,但是,基本 URL 似乎不適用於該站點。 我還沒有更改 DNS,所以在 FTP 上使用 IP 和子文件夾。

應用程序/配置/config.php

$config['base_url'] = 'http://xxx.xxx.xx.xxx/blah.com/';

也試過

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/blah.com/';

但是當網站加載時,由於它正在嘗試加載而缺少 css

<link href="/assets/css/global.css" rel="stylesheet" type="text/css" media="all" />
<link href="/assets/css/public.css" rel="stylesheet" type="text/css" media="all" />

等。

即使瀏覽器中的 URL 顯示

http://xxx.xxx.xx.xxx/blah.com/

資產和東西正在嘗試加載

http://xxx.xxx.xx.xxx/

這是我的 htaccess 文件。

# Deny access to the htaccess file
<FILES .htaccess>
order allow,deny 
deny from all
</FILES>

# Prevent these script from executing anything
Options -ExecCGI
AddHandler cgi-script .pl .py .jsp .shtml .sh .asp .cgi

# Make it so sessions are available on all sub-domains
#php_value session.cookie_domain .prelicensetraining.com

# Prevent directory browsing
Options -Indexes

# Code Igniter Clean URL Rewrites
RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ index.php?/$1 [L]  

額外說明:最初在 A2 的新虛擬主機上遇到 500 內部服務器錯誤的問題。 打開票證並從支持人員那里收到以下信息。 現在它正在連接到 db,但正如我上面提到的,基本 URL 設置無法正常工作。

“這是由於該軟件使用了較舊的 mysql 擴展,PHP 7+ 不再支持該擴展。我們安裝了 cPanel 的 MultiPHP 系統並將 blah.com 設置為使用 PHP 5.6,然后將 application/config/database.php 文件更新為使用 'localhost' 作為數據庫主機,我們現在在http://xxx.xxx.xx.xx/blah.com/得到一個登錄頁面。”

您沒有在 HTML 代碼中使用base_url ,您當前正在“手動”加載資產:

<link href="/assets/css/global.css" rel="stylesheet" type="text/css" media="all" />

開頭的/告訴瀏覽器從根文件夾加載資產。

你可以使用base_url()函數來生成鏈接,如果你加載了 URL helper,這個函數是可用的,你可以像這樣使用它:

base_url('assets/css/global.css');

這將返回:

http://xxx.xxx.xx.xxx/blah.com/assets/css/global.css

所以像這樣使用它:

<link href="<?=base_url('assets/css/global.css');?>" rel="stylesheet" type="text/css" media="all" />

<?=<?php echo相同

您可以使用以下代碼加載 URL 助手:

$this->load->helper('url');

請試試這個

<link href="<?php echo base_url();?>assets/css/global.css" rel="stylesheet" type="text/css" media="all" />

還要在檢查元素中檢查它或右鍵單擊您的站點,然后單擊查看頁面源以查看文件的正確路徑並進行相應更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM