Codeigniter + CSS not working, maybe baseurl

This question has been asked several times, but I have researched and still cannot solve it. In one of the files of my view, I have (link to my css):

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

The css file is located in:

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

I also tried -www up css in the same folder in -www and using it directly

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

My url base is set to "" because I am developing locally. This is problem? I am using a wamp server.

So what is the problem? Can anyone help?

+4
source share
4 answers

You cannot put your CSS files or files in a browser in the application folder because it is protected for security reasons with the .htaccess file set to "Deny All". Your CSS, JS, image files, etc. must be located outside the application folder.

Put your CSS file in the css folder in the “www” folder so that it is not inside the “application” or “system”. Then make sure that you use the following (note the slash for the 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] 
+6
source

Whereas, there are several ways to get rid of a cat.

Quick fix without using 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

    • applications

      • view
      • (...)
    • System

    • assets
      • CSS
        • screen.css
+1
source

You must put all your asset files (images, js, css, etc.) in a separate folder in the root of the site ( outside the application folder ). Create a folder called “files” and add the following line to your .htaccess file in the root of the site:

 # Allow these directories and files to be displayed directly: # - index.php (DO NOT FORGET THIS!) # - robots.txt # - favicon.ico # - Any file inside of the files/ - js/, or css/ directories RewriteCond $1 ^(index\.php|files) 

This way you will have direct access to the file folder (and any file folder inside) through the URL.

+1
source

I also ran into the same problem on Windows. On a Mac, it was easy. If you are trying to exclude index.php from the url, I came across 400 Bad Request Error . This is later fixed with the slash RewriteRule index.php prefix, as shown below

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

to

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

Going forward, faced with another question: Failed to load assets / static files. In addition, I had a folder with resources at the root level. I saw a solution similar to adding “assets” to a RewriteCond to eliminate the use of rewriteRule. as,

 RewriteCond $1 !^(index\.php|assets) #It does not work for me 

But that will not work. I have 404 not found error. I later found a solution for this, since

 RewriteCond $1 !^(index\.php|\/assets) #Working! 

And My Rewrite scripts can be found here:

  RewriteEngine on RewriteCond $1 !^(index\.php|\/assets) RewriteRule ^(.*)$ /index.php/$1 [L] 

Hope this helps and saves a lot of time! :)

+1
source

All Articles