I have the following directory structure of Codeigniter Folder. You can see that I have put all my assets in the assets
folder at the root of the application.
Change your base_url
to the following:
echo base_url("assets/css/file-name-here.css");
You want to pass the URL string to the base_url
function. This way, you can change $config['base_url']
to whatever you want and it will append the string to that URL properly.
You have multiple options here. The easiest one is to move the assets folder to the same level as the application so that your directory structure is:
Because the assets folder is not in a folder with the .htaccess with Deny From All
it won't be blocked by your web server.
Alternatively you can add an .htaccess file in the assets folder with the following rule:
# /assets/.htaccess
Allow from all
I haven't tested this but I think it should work.
Another option is to change the .htaccess and put an exception on the assets folder but it's a very bad idea (with security implications) to remove the Deny From All
without writing alternate rules to lock all folders that shouldn't be accessible.
Also, set your base_url
to the folder containing application, system and assets directories (this folder contains Codeigniter's bootstrap/front controller index.php).
Additionally, I would advise you to echo your urls using the base_url() function:
base_url("assets/css/bootstrap.min.css");
OR to call a controller/route
base_url("controller/method");
The base_url function takes into account the value of $config['index_page']
as well as the necessary leading/trailing slashes.
As an addition to the answer of grim. If you have your rewrite engine on you should have the following in your root .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>