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.

2
  • Could you show the css href <link rel="stylesheet" type="text/css" href=""> Commented Dec 11, 2013 at 3:36
  • edited to show css href Commented Dec 11, 2013 at 3:38

4 Answers 4

0

You can try this, example

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

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

7 Comments

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.
You want to use another css folder's css file?
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.
I think you can reference this stackoverflow.com/questions/5450095/…
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 :/
|
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');?>"/>

2 Comments

Still no dice. Would you happen to have the .htaccess file that was working for you with xampp that I could compare with?
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?
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)

Comments

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

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.