views:

478

answers:

1

I am just starting out with Codeigniter. I have referenced the css file in the corresponding views file but it fails to link. This is the code I have used to reference the css file.

<link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css" media="screen"/>

I tested the css code by inserting it between & and it works. Just can't get the linking to work.

+2  A: 

I'm sorry, rewriting the whole answer as I remember what I had to do and which should fix your problem.

Check your .htaccess file in the top level directory, I added exceptions for js/css/images dirs otherwise they would have been rewritten:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
kemp
Okay tried both - still no luck!Final html redering for:base_url() shows www.domain.com/css/style.csssite_url shows www.domain.com/index/css/style.css
strangeloops
I used your code for .htaccess file and this is the error I get:Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
strangeloops
You should check the error log of the webserver to see the specific error that caused the Internal Server Error. Also, what happens if you try to reach `www.domain.com/css/style.css` directly?
kemp
If I use www.domain.com/css/style.css directly, it gives me a 404 error. If I use this htaccess code it I don't get the internal error when I go to my domain www.obsia.com but ofcourse still does not link the css. RewriteEngine onRewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)RewriteRule ^(.*)$ /index.php?/$1 [L]
strangeloops
Wait here might be the issue (looking at my error log files). It looks under /home/obisac5/public_html/css to find the css file. Do I change the base url to the above url or will it cause the problem when add other bits of codes to complete the website?
strangeloops
No you can't use absolute paths in HTML pages, look for other errors related to htaccess rewriting in the log
kemp
I just realised that my main index is in the public_html folder which is at the root level. All my other codeigniter files are at the same level as the public_html file.
strangeloops
Hey kemp, thanks for being so patient with me. It was error on my part for not having the files on the same level - didnt realize it! It works fine now. Thanks!
strangeloops
Good to hear :)
kemp