CodeIgniter Forums
Where should I put my images, css and js files inCodeIgniter? - 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: Where should I put my images, css and js files inCodeIgniter? (/showthread.php?tid=30753)



Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]Stephane02[/eluser]
Hi,

I have a problem accessing my resources (images, js, css) in CodeIgniter.
I made 3 folders /css /js and /images in the CI root dir (where index.php
and .htaccess are located) but I get CI error not found each time I try to reach
my files (css, images and js files) in a web browser.

To solve the problem, I have made a subdomain I called /assets and put in
/css /js and /images and their content and when going to http://assets.domain.com/css/style.css it's not reachable until I remove the .htaccess file.

Can you help me to solve my problem? Here is the .htaccess content:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|scripts|system)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Thank you,

Stephane


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]mattpointblank[/eluser]
I tend to structure my CI projects like this (with an assets/css folder in the root directory) and reference everything like this:

Code:
<img src="&lt;?php echo base_url(); ?&gt;assets/img/logo.jpg" />



Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]WanWizard[/eluser]
Your rewrite condition doesn't exclude js and images, so requests for both will be rewritten to index.php.

And I don't think it's a good idea to exclude the entire system directory as well, you don't want those files internet accessable.


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]Stephane02[/eluser]
[quote author="WanWizard" date="1274809658"]Your rewrite condition doesn't exclude js and images, so requests for both will be rewritten to index.php.

And I don't think it's a good idea to exclude the entire system directory as well, you don't want those files internet accessable.[/quote]

So, what should I do ?


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]Stephane02[/eluser]
Can you help me ?


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]frist44[/eluser]
Like matt said, I think most people place them off the root, so it's parallel with the systems folder. I happen to just have them in the root, so base_url() . 'img/image.jpg'. In this case, put the following in your .htaccess and avoid itemizing the folders you have.

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


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]jshultz[/eluser]
I'm agreeing with Matt and Frist. I have a folder on the same level as application and system called assets. Underneath assets are subfolders for js, css, and images.


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]SitesByJoe[/eluser]
Same here. My .htaccess is very similar to Frist's.

With the folder at the root, you could hardcode HTML like this:

Code:
<a href="/assets/images/...">

To be more flexible it's advisable to do things like:

Code:
&lt;?php echo anchor('assets/images/...', 'Link Text'); ?&gt;

If you can't get at your files after repairing your .htaccess file you may want to double check permissions too.


Where should I put my images, css and js files inCodeIgniter? - El Forum - 05-25-2010

[eluser]Stephane02[/eluser]
Thanks a lot for your kind helps!!!! It works fine Big Grin