CodeIgniter Forums
Not able to access my assets folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Not able to access my assets folder (/showthread.php?tid=58022)



Not able to access my assets folder - El Forum - 05-07-2013

[eluser]carlosgoce[/eluser]
I have tried everything and i just cant do it.

This is my info:
Project: gestion
Url: localhost:8085/gestion/
Assets folder: application/assets/
/css
/js
/etc

My .htaccess file looks something like this:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /gestion/index.php/$1 [L]

I create a constant on constants.php:
Code:
define('ASSETSPATH', APPPATH.'assets');

So then i call from the views to my css with this:
Code:
<link href="<?=ASSETSPATH?>/css/bootstrap.css" rel="stylesheet">

But it says "forbidden access" on the javascript console.

So i try to give access to assets folder with a new .htaccess on assets folder with the next content:
Code:
Options +Indexes

But it's not working. I tried a lot of things and i can't find a way to load my assets content.

Thank you for your time.


Not able to access my assets folder - El Forum - 05-07-2013

[eluser]RogerMore[/eluser]
Hello carlos,

I think you have to change your approach to your problem. I will explain to you what to do to access your assets from your views.

First of all, the applications folder is not the right place to put your assets. You should move the assets folder to the root of your CI installation.

Then change the rewrite conditions in the .htaccess so that a call to an assets will not be routed to the index.php, like so:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/etc|robots\.txt)
RewriteRule ^(.*)$ /gestion/index.php/$1 [L]


Finally call your css file using base_url(). Base_url is a function from the URL helper (load the Url helper first) and will return 'http://localhost:8085/gestion/'.

Code:
<link href="<?php echo base_url('assets/css/bootstrap.css'); ?>" rel="stylesheet">

This should return 'http://localhost:8085/gestion/assets/css/bootstrap.css'.

Hope this helps... Smile

Greetz,

Roger


Not able to access my assets folder - El Forum - 05-07-2013

[eluser]carlosgoce[/eluser]
Thank you for your help. It works... for the Javascript. But the CSS still not working. I can't wonder why.

I have my index like this:
Code:
<base href="<?=base_url()?>" target="_self">

So i only call it once.
This is working:
[removed][removed]
[removed][removed]

This is NOT working:
Code:
[removed][removed]
[removed][removed]

Javascript console returns:
Code:
GET http://localhost:8085/gestion/assets/css/bootstrap-min.css 404 (Not Found)
GET http://localhost:8085/gestion/assets/css/bootstrap-responsive.css 404 (Not Found)

Of course they exist in the designed folder.

Maybe it's something wrong with the htaccess file?
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/ficheros|assets/img|robots\.txt)
RewriteRule ^(.*)$ /gestion/index.php/$1 [L]



Not able to access my assets folder - El Forum - 05-07-2013

[eluser]carlosgoce[/eluser]
I just restarted apache and know it's working.

Thank you very much.


Not able to access my assets folder - El Forum - 05-08-2013

[eluser]RogerMore[/eluser]
Hi carlos,

Glad to be of some help. Don't forget to push the 'solution' button though... :-P

Greetz,

Roger