codeigniter基目录中的css / image / js文件问题

I've been stumbling around setting up the .htaccess file to redirect all requests to the index.php file under xampp in windows 7(removing index.php from the url), and think I may have created an issue for myself...but then again it may be unrelated.

I seem to be having an issue referencing the directories I have setup in the base directory for css, images, and js. I have tracked the issue down, but not sure how to resolve it just yet. If I navigate back a directory ../css/stye.css vs. css/style.css then the stylesheet will load. If I type in the base url or base url with index function call, everything loads as expected:

http://localhost/site
http://localhost/site/home

Now when I add the controller method name

http://localhost/site/home/index

my css is no longer included (until I go into firebug and navigate back a directory)

The code in my .htaccess file (that I found to work with xampp) located in my base directory is as follows:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I openly admit to not not knowing as much as I probably should about .htaccess files.

CSS href:

<link rel="stylesheet" type="text/css" href="css/jmw.css" />

EDIT

.htaccess file edited as suggested by Rajeev Ranjan

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

I am operating off of the assumption that every view is working as if it where the index.php file itself and accessing directories in this manner. Everything works when using the base_url() function in front of the stylesheet, javascript, or image calls, but I am attempting not to rely on base_url() function in multiple locations of the view file.

Finally figured this out! After working with codeigniter for the past few months and gaining a broader understanding about what exactly was going on in the .htaccess file, the solution was obvious. Since the .htaccess file was pointing to the controllers directory, whenever I would attempt to access my images/js/css files from '/images', etc it was looking inside the controllers directory.

To solve this case I set base_url = '' in config.php and where I call the images/js/css I transverse back a directory '../images/file.png'. Simple solution, just took a bit for my brain to click over :)

You can try this, example

<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/jmw.css" />

I also faced this problem.please put this line in your .htaccess file

RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js)

ie. allow css .

Wampp :

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

and calling css By

<link rel="stylesheet" href="<?php echo base_url();?>css/main/style.css"/>

or,

<link rel="stylesheet" href="<?php echo base_url('css/main/style.css');?>"/>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js)
RewriteRule ^(.*)$ ./index.php/$1 [L]

In second line ie;

RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js)

You have to pass the folder name of your css, js and image files like:
RewriteCond $1 !^(index\.php|images|robots\.txt|css|img|js|assets|images)