Undefined Variable
Undefined Variable

Reputation: 4267

Unable to load css files in codeigniter 3

I have the CI installation configured in my apache conf and hosts files such that I can open it by pointing my browser to:

http://mysite/

Above URL will open the index file configured and everything works fine.

Now in this CI installation I added a CSS file at:

application/assets/css/site.css

And in my config file I added:

$config['base_url'] = 'http://mysite/';

If I do an echo $base_url() I get http://mysite/ so it works fine.

Now to load the css file I do $siteCss = base_url('assets/css/site.css')

This shows me http://mysite/assets/css/site.css as expected, but if I open that URL in browser it gives 404 error.

In my .htaccess I have added a few lines to remove index.php from the URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

How can I correctly load my css files in this setup?

Any help is greatly appreciated!

Upvotes: 1

Views: 439

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

Put your assets directory in project root directory and this is best practice. so your site.css path should be

assets/css/site.css

instead of

application/assets/css/site.css

and now test. Now $siteCss = base_url('assets/css/site.css') will work

Upvotes: 1

Related Questions