0

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.

whitwhoa
  • 2,389
  • 4
  • 30
  • 61

4 Answers4

0

You can try this, example

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

lighter
  • 2,808
  • 3
  • 40
  • 59
  • Yes, this would solve the issue but the folders were moved into the base directory to resolve the need for using base_url() within the code. – whitwhoa Dec 11 '13 at 03:47
  • You want to use another css folder's css file? – lighter Dec 11 '13 at 03:53
  • The issue is not only with the css directory but the image and js directories as well. If I used base_url() before the calls to the css and js directories, I would still have to go into the code and add base_url() in front of every image I have in every view...this is what I was trying to get away from when i originally moved the directories into the base directory. – whitwhoa Dec 11 '13 at 03:55
  • I think you can reference this http://stackoverflow.com/questions/5450095/codeigniter-simple-base-url-question – lighter Dec 11 '13 at 03:59
  • Thank you, but again...the issue is not solely about the css directory, but the js, and images directory as well. I would rather not use base_url() for every image that's displayed in the view :/ – whitwhoa Dec 11 '13 at 04:07
  • You can try this ``. Or show your project architecture. – lighter Dec 11 '13 at 04:09
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42911/discussion-between-lighter-and-nullreference) – lighter Dec 11 '13 at 05:27
0

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');?>"/>
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41
  • Still no dice. Would you happen to have the .htaccess file that was working for you with xampp that I could compare with? – whitwhoa Dec 11 '13 at 04:26
  • 1
    I had high hopes but this still didn't solve my issue. If I mis-configured something in the config.php or routes.php file could this possibly be causing my issue? – whitwhoa Dec 11 '13 at 04:39
0
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)
0

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 :)

whitwhoa
  • 2,389
  • 4
  • 30
  • 61