Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 997
ZhijieWang Avatar asked Jan 14 '23 19:01

ZhijieWang


2 Answers

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]
like image 57
cryptic ツ Avatar answered Jan 21 '23 03:01

cryptic ツ


Bearing in mind there are several ways to skin a cat.

Quick fix without messing with htaccess. Use base_url() or site_url():

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

And use the following file structure:

  • www

    • application

      • views
      • (...)
    • system

    • assets
      • css
        • screen.css
like image 36
AaronSantos Avatar answered Jan 21 '23 04:01

AaronSantos