将网站从一个域迁移到另一个域并托管时,CodeIgniter 未加载 CSS 和 JS
CodeIgniter not loading CSS and JS while migrating website from one domain to another domain and hosting
正在迁移网站。我无法在我的 Codeigniter 项目中加载 CSS 和 JS 文件。
文件夹结构:
home > username > public_html > application > [ cache , config , controller, core, ... ]
home > username > public_html > media > admin > [ attachment, css, datepicl, ...]
home > username > public_html > media > front > asset > [css, fonts, img, ...]
home > username > public_html > media > uploads > [associatepartner, banner, ..]
home > username > public_html > system > [core, database, ..]
config.php
< 配置 < 应用程序 < public_html
$config['base_url'] = 'http://localhost/domain.com';
header.php
<布局<正面<视图<应用程序
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/reset.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/style.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/responsive.css">
求助。谢谢! (如果我需要提供更多详细信息,请告诉我)
EDIT: view-source:http : // domain.com/ (请忽略 http 之间的空格。)
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/reset.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/style.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/responsive.css">
编辑:添加了constants.php
constants.php
< 配置 < 应用程序 < public_html
defined('BASEPATH') OR exit('No direct script access allowed');
if (sSITE_MODE == 'live') {
define('URL', 'https://www.theother2thirds.net/');
} else if (sSITE_MODE == 'beta') {
define('URL', 'https://www.theother2thirds.net/');
} else {
define('URL', 'http://localhost/theother2thirds/');
}
您的base_url定义为
$config['base_url'] = 'http://localhost/domain.com';
您需要在您的控制器中加载 url 助手,或者您可以自动加载它,然后您可以使用函数 base_url()
.
那么您可以选择使用
<link rel="stylesheet" type="text/css" href="<?= base_url('asset/css/bootstrap.min.css');?>">
或者您可以分配 FRONT_MEDIA_URL
defined('FRONT_MEDIA_URL') || define('FRONT_MEDIA_URL', base_url());
但是您需要事先加载 url 帮助程序,并且您没有显示声明的位置,但这是您自己弄清楚的。
因新信息而更新
看看你能不能用这个
现在我不知道您在哪里定义 sSITE_MODE 但这是一个选项,可以帮助您在网站中使用 base_url()...
在application/config/config.php中你可以做类似
的事情
defined('sSITE_MODE ') || define('sSITE_MODE', 'live');
if (sSITE_MODE == 'live') {
$migration_url = 'https://www.theother2thirds.net/';
} else if (sSITE_MODE == 'beta') {
$migration_url = 'https://www.theother2thirds.net/';
} else {
$migration_url = 'http://localhost/theother2thirds/';
}
$config['base_url'] = $migration_url;
或者只定义正确的常量并使用它。您的链接中有 FRONT_MEDIA_URL,然后您正在谈论使用 URL。您需要使用正确的。
正在迁移网站。我无法在我的 Codeigniter 项目中加载 CSS 和 JS 文件。
文件夹结构:
home > username > public_html > application > [ cache , config , controller, core, ... ]
home > username > public_html > media > admin > [ attachment, css, datepicl, ...]
home > username > public_html > media > front > asset > [css, fonts, img, ...]
home > username > public_html > media > uploads > [associatepartner, banner, ..]
home > username > public_html > system > [core, database, ..]
config.php
< 配置 < 应用程序 < public_html
$config['base_url'] = 'http://localhost/domain.com';
求助。谢谢! (如果我需要提供更多详细信息,请告诉我) EDIT: view-source:http : // domain.com/ (请忽略 http 之间的空格。) 编辑:添加了header.php
<布局<正面<视图<应用程序
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/reset.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/style.css">
<link rel="stylesheet" type="text/css" href="<?php echo FRONT_MEDIA_URL; ?>asset/css/responsive.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/reset.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/style.css">
<link rel="stylesheet" type="text/css" href="http : / / localhost/domain/media/front/asset/css/responsive.css">
constants.php
constants.php
< 配置 < 应用程序 < public_htmldefined('BASEPATH') OR exit('No direct script access allowed');
if (sSITE_MODE == 'live') {
define('URL', 'https://www.theother2thirds.net/');
} else if (sSITE_MODE == 'beta') {
define('URL', 'https://www.theother2thirds.net/');
} else {
define('URL', 'http://localhost/theother2thirds/');
}
您的base_url定义为
$config['base_url'] = 'http://localhost/domain.com';
您需要在您的控制器中加载 url 助手,或者您可以自动加载它,然后您可以使用函数 base_url()
.
那么您可以选择使用
<link rel="stylesheet" type="text/css" href="<?= base_url('asset/css/bootstrap.min.css');?>">
或者您可以分配 FRONT_MEDIA_URL
defined('FRONT_MEDIA_URL') || define('FRONT_MEDIA_URL', base_url());
但是您需要事先加载 url 帮助程序,并且您没有显示声明的位置,但这是您自己弄清楚的。
因新信息而更新 看看你能不能用这个 现在我不知道您在哪里定义 sSITE_MODE 但这是一个选项,可以帮助您在网站中使用 base_url()...
在application/config/config.php中你可以做类似
的事情defined('sSITE_MODE ') || define('sSITE_MODE', 'live');
if (sSITE_MODE == 'live') {
$migration_url = 'https://www.theother2thirds.net/';
} else if (sSITE_MODE == 'beta') {
$migration_url = 'https://www.theother2thirds.net/';
} else {
$migration_url = 'http://localhost/theother2thirds/';
}
$config['base_url'] = $migration_url;
或者只定义正确的常量并使用它。您的链接中有 FRONT_MEDIA_URL,然后您正在谈论使用 URL。您需要使用正确的。