2011-08-09 69 views
1

我有沒有/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 ...

回答

7

這是因爲你的應用程序文件夾不在您的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" />