ZhijieWang ZhijieWang - 2 years ago 134
CSS Question

Codeigniter + CSS not working well, possible baseurl

This question has been asked several times, but I researched and still can't solve it. In one of my view file, I have (referencing to my css):

link rel="stylesheet" type="text/css" href="/application/views/screen.css"


The css file is in:

- www
- application
- view
- css
- screen.css
- system


I also tried to setup the css in the same folder under
-www
and use it directly by

link rel="stylesheet" type="text/css" href="css/screen.css"


My base
url
is set to
""
because I develop locally. Is this the issue? I'm Using wamp server.

So what is the problem? Can anyone help?

Answer Source

You can't put your CSS files or files to be served to browser in the application folder as it is protected for security reasons with a .htaccess file set to 'Deny from All' Your CSS, JS, image files etc, need to be outside of the application folder.

Put your CSS file in a folder called 'css' in the 'www' folder so it is NOT inside 'application' or 'system'. Then make sure you use the following (notice the leading slash, denoting an absolute URL):

href="/css/screen.css"

Use this instead:

# If your default controller is something other than
# "welcome" you should probably change this
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download