codeigniter 404未找到CSS [英] codeigniter 404 not found CSS
问题描述
我在codeigniter中有一个关于CSS url的问题:
I have an issue about CSS url in codeigniter:
在文件控制器中我有文件 admin / home.php
In file controllers I have the file admin/home.php
in home.php:
in home.php :
class Home have function index() and function login().
function login() { redirect('admin/home');}
:
$routes['admin'] = 'admin/home/login';
$routes['admin/home'] = 'admin/home/index';
和错误:
Request URL:http://congnghehatnhan.tk/admin/public/css/bootstrap.min.css
Request Method:GET
Status Code:404 Not Found
推荐答案
描述您的网站资源时:
<link href="public/css/bootstrap.min.css" rel="stylesheet">
当您使用以下网址时会出现问题:
Your problem occurs when you are on the following URL:
http://congnghehatnhan.tk/admin/
直接使用样式表声明的副作用会导致样式表当前链接到:
A side-effect of using the stylesheet declaration directly as you have, results in the fact that the stylesheet is currently linking to:
http://congnghehatnhan.tk/admin/public/css/bootstrap.min.css
您希望它链接到:
http://congnghehatnhan.tk/public/css/bootstrap.min.css
注意从网址中缺少的管理
Notice the missing admin segment from the URL.
通过CodeIgniter引用资源时,您希望使用base_url()方法来生成正确的链接。因此,在不了解更多关于您的代码库的情况下,我认为将原始样式表声明更改为以下内容应该可以解决您的问题:
When referencing assets via CodeIgniter, you want to use the base_url() method in order to generate the correct link. Thus, without knowing more about your codebase, I believe that changing the original stylesheet declaration to the following should fix your issue:
<link href="<?php echo base_url('public/css/bootstrap.min.css');?>" rel="stylesheet">
请注意,上述方法适用于所有引用资产的实例。
Please note that the approach above applies to all instances of referencing assets.
这篇关于codeigniter 404未找到CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!