我正在开发一个codeigniter项目.我有关于CSS的问题.css以下列方式包含在标题中:
<link href="http://localhost/ebookazine/assets/css/reset.css" rel="stylesheet" type="text/css" />
<link href="http://localhost/ebookazine/assets/css/typography.css" rel="stylesheet" type="text/css" />
<link href="http://localhost/ebookazine/assets/css/FlashStatus.css" rel="stylesheet" type="text/css" />
<link href="http://localhost/ebookazine/assets/css/webshop.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
但没有css链接工作.有人帮忙吗?
首先,检查你的.htaccess文件是否看起来像这样(特别是|assets|部分很重要):
rewriteengine on
rewritecond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
这允许assets公共访问文件夹中的文件.
接下来,确保视图中的路径使用该base_url()命令,例如:
<link href="<?php echo base_url(); ?>assets/css/typography.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
这样,无论您是在本地计算机上还是在Web服务器上进行测试,视图都将始终使用正确的绝对URL.