2

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

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.