5

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.

3
  • 1
    Do you have the url helper loaded? $this->load->helper('url'); ? Commented Feb 6, 2010 at 12:50
  • yes I did using $this->load->helper('url') I also autoloaded it. I seem to have the same problem with the images, they don't load either. my css & images files are saved in css & images folder respectively. They are stored on the same level at the system file - root. I hope this can shed more light. Commented Feb 6, 2010 at 12:55
  • is this link_tag working something like, <?php echo link_tag('resources/style.css');?> inside head tag Commented Jul 21, 2016 at 4:17

2 Answers 2

8

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]
Sign up to request clarification or add additional context in comments.

8 Comments

Okay tried both - still no luck! Final html redering for: base_url() shows www.domain.com/css/style.css site_url shows www.domain.com/index/css/style.css
I used your code for .htaccess file and this is the error I get: Internal Server Error The 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.
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?
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 on RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css) RewriteRule ^(.*)$ /index.php?/$1 [L]
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?
|
0

(two years later)... For the RewriteRule in the .htaccess file, you want your path starting with your server's root, so for example, if you're using WAMP, and you have a folder at C:\wamp\www\my_site\my_new_app then your RewriteRule should say

RewriteRule ^(.*)$ /mysite/my_new_app/index.php/$1 [L]

Just throwing that out there for us CI newbs

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.