开发者

Problem with removing index.php on Codeigniter didn`t load my css and js

Currently I tried to remove index.php on codeigniter url. I installed my codeigniter on localhost/jqm/withci . Then I write .htaccess to remove index.php and it worked well. .htaccess file :

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

But Im having some problem, my css file and js wont load.. My conroller is

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');
    }
}

my view for head_view is :

<!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>

I tried to use base_url() but it didnt load my css and js. Thank you.. PS : Im using css and js file for jQuery Mobile. We can load it from CDN repositories, but I want to make it loadable from my own directory in case I want to load custom css or js in future


In your .htaccess file add the folder which contains the JavaScript and CSS to the rewrite condition, something like:

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

Currently those files aren't loading, instead they're pointing to your index.php file.


Try adding this to your rewrite rules to prevent the rewrite from occuring on all files and directories:

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


you can set a new config variable at the config file and but the path for the css/js file on it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜