base url for code igniter 站点不工作

base url for code igniter site not working

CodeIgniter 的新手,正在尝试。

年长(5 岁?)CI 网站。将其移至 A2 的新虚拟主机并进行设置。

主页出现,但是,基础 URL 似乎不适用于该站点。我还没有更改 DNS,所以使用 FTP.

上的 IP 和子文件夹

application/config/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?/ [L]  

额外说明:最初在 A2 的新虚拟主机上遇到 500 内部服务器错误。打开票证并从支持人员那里收到以下信息。现在它正在连接到数据库,但正如我上面提到的,基础 URL 设置无法正常工作。

"This was due to the software using an older mysql extension, which is no longer supported under PHP 7+. We installed cPanel's MultiPHP system and set blah.com to use PHP 5.6, then updated the application/config/database.php file to use 'localhost' as the database host and we now get a login page at http://xxx.xxx.xx.xx/blah.com/ ."

请试试这个

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

同时在 检查元素 中检查它,或者右键单击您的站点并单击 查看页面源代码 以查看正确的路径文件并进行相应更改。

您没有在 HTML 代码中使用 base_url,您目前正在 "manually" 加载资产:

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

开头的 / 告诉浏览器从根文件夹加载资源。

可以使用base_url()函数生成链接,如果加载URL助手就可以使用这个函数,可以这样使用:

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

这将 return:

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');