在CodeIgniter中没有/index.php/链接到CSS

时间:2011-08-09 23:34:08

标签: php codeigniter

我有没有/index.php/ URL的CodeIgniter,我想在视图中链接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]

我的链接:

<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/views/metrohacker/style.css" />

使用/index.php/它可以工作,但我想要简单的URL ...

1 个答案:

答案 0 :(得分:7)

这是因为你的应用程序文件夹不在你的htaccess文件中没有重写的文件夹列表中。

RewriteCond $1 !^(index.php|images|robots.txt|system|user_guide)

我会将CSS文件保存在应用程序的根目录中,而不是在views文件夹中。我也会对你的JavaScripts和图像做同样的事情。这样你的文件夹结构就像:

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" />