2011-06-10 14 views
2

目前我試圖刪除codeigniter url上的index.php。我在localhost/jqm/withci上安裝了codeigniter。然後我寫.htaccess刪除index.php,它運作良好。 .htaccess文件:在Codeigniter上刪除index.php的問題沒有加載我的CSS和js

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /jqm/withci/index.php/$1 [L] 

但我m having some problem, my css file and js won噸負荷..我的電腦板是

class Home extends CI_Controller { 
    function __construct() { 
     parent::__construct(); 
     $this->load->helpers('url'); 
    } 

    function index() { 
     $this->load->view('head_view'); 
     $this->load->view('main_view'); 
     $this->load->view('foot_view'); 
    } 
} 

我對head_view的看法是:

<!DOCTYPE HTML> 
<html> 
    <head> 
    <meta name="viewport" content="width=320; user-scalable=no" /> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> 
    <title>jQuery Mobile with Codeigniter</title> 
     <link rel="stylesheet" href="<?php echo base_url();?>jquery.mobile/jquery.mobile-1.0a4.1.css" type="text/css" charset="utf-8" /> 
     <script type="text/javascript" src="<?php echo base_url();?>jquery.mobile/jquery-1.5.2.js"></script> 
     <script src="<?php echo base_url();?>jquery.mobile/jquery.mobile-1.0a4.1.js"></script> 

    <!-- CDN Respositories: For production, replace lines above with these uncommented minified versions --> 
    <!-- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />--> 
    <!-- <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>--> 
    <!-- <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>--> 

    </head> 
    <body> 

我試圖用BASE_URL(),但它沒有t load my css and js. Thank you.. PS : I m使用jss Mobile的css和js文件。我們可以從CDN存儲庫加載它,但是我希望從我自己的目錄中加載,以防將來加載自定義css或js

回答

4

在您的.htaccess文件中,將包含JavaScript和CSS的文件夾添加到重寫條件,如:

RewriteCond $1 !^(index\.php|images|jquery\.mobile|robots\.txt) 

目前這些文件未加載,而是指向您的index.php文件。

+1

非常感謝.. 這是我的錯,我不知道mod_rewrite .. – justmyfreak 2011-06-10 12:51:23

3

嘗試添加以下內容到重寫規則,以防止重寫從存在的所有文件和目錄:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
0

你可以在配置文件中設置一個新的配置變量,但對於CSS/JS路徑檔案