链接到CodeIgniter中没有/index.php/的CSS
问题描述:
我有没有/index.php/ URL的CodeIgniter,我想链接视图中的CSS文件。链接到CodeIgniter中没有/index.php/的CSS
我的.htaccess:
RewriteEngine on
RewriteCond $1 !^([a-zA-z0-9/])
RewriteRule ^(.*)$ index.php [L]
RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide)
RewriteRule ^(.*)$ index.php/$1 [L]
我的链接:
随着/index.php/它的工作原理,但我想简单的URL ...
答
这是因为你的应用程序文件夹不在您的htaccess文件中未被重写的文件夹列表中。
RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide)
我会保持你的CSS文件在应用程序的根目录而不是在视图文件夹。我也会对你的JavaScript和图片做同样的事情。这样,你的文件夹结构是这样的:
root/
application/
assets/
css/
js/
images/
system/
...
确保将资产文件夹添加到您的.htaccess:
RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide|assets)
那么你不必担心的index.php做的路由,你可以加载一个CSS文件像这样:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/style.css" />