0

My css file present in css/style.css :

body {
 background-color: #fff;
 margin: 40px;
 font-family: 'Lucida Grande', Verdana, Sans-serif;
 font-size: 14px;
 color: #4F5155;
}

When I run the site in a browser, there is no styling to the controller page , and the path to the css file returns this:

<html>
<head>
<title>404 Page Not Found</title>
<style type="text/css">

body {
background-color:   #fff;
margin:             40px;
font-family:        Lucida Grande, Verdana, Sans-serif;
font-size:          12px;
color:              #000;
}
</style>
</head>
<body>
<div id="content">
    <h1>404 Page Not Found</h1>
    <p>The page you requested was not found.</p>    </div>
</body>
</html>

Any ideas on what's going on here ?

2
  • check your apache rewrite, apache error log, it should stated why file not found (such as refer to wrong DocumentRoot or so) Commented Nov 24, 2010 at 10:22
  • The error log doesn't give anything. The access log gives this : 127.0.0.1 - - [24/Nov/2010:15:58:28 +0530] "GET /c/index.php HTTP/1.1" 200 688 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12" 127.0.0.1 - - [24/Nov/2010:15:58:29 +0530] "GET /c/index.php/css/style.css HTTP/1.1" 404 539 "localhost/c/index.php" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12" Commented Nov 24, 2010 at 10:30

1 Answer 1

1

Your stylesheet can't be found, most likely because it isn't on the path you think it is.

Things to check:

  • What do you think your stylesheet's path is (i.e. what did you type in the browser to get that 404 error?)

  • Where is the file in the filesystem in relation to your CodeIgniter root?

  • Are you using a .htaccess file? If so, what's in it? The .htaccess redirection done in CodeIgniter can confuse you.

The "standard" setup for CodeIgniter css files is this:

  • Save your css file in a "css" directory in the root of your CodeIgniter install, i.e. alongside the top-level index.php and .htaccss.

  • Make sure your .htaccess rewrite excludes the css directory, e.g.: RewriteCond $1 !^(index\.php|images|robots\.txt|css) <-- note "css" is among the patterns to avoid rewrites for here. Otherwise CodeIgniter will think that "css" is a controller, not the actual directory on disk.

  • Include your CSS file in your HTML file using something like: <link rel="stylesheet" href='<?php echo base_url()?>css/style.css' type="text/css" media="screen, projection" />.

  • Obviously, make sure that your base_url is set correctly in your application's config\config.php file.

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

2 Comments

Ah ! Got it ! My htaccess file was missing the css directory! Thanks so much !
@Hardik No problem. That's why you weren't seeing an error in the Apache error log; at the Apache level, there was no error. Apache's .htaccess mechanism was successfully pointing the request for the css file at CodeIgniter's main entry point. Then CodeIgniter was trying to find a controller called "css", failing, and manually throwing the CodeIgniter custom 404 page/error back at you. (If you look in application\errors\error_404.php, you'll see the source of the 404 page you were being shown.)

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.