Where should I put my images, css and js files inCodeIgniter? |
[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 Thank you, Stephane
[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="<?php echo base_url(); ?>assets/img/logo.jpg" />
[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.
[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 ?
[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]
[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.
[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: <?php echo anchor('assets/images/...', 'Link Text'); ?> If you can't get at your files after repairing your .htaccess file you may want to double check permissions too.
[eluser]Stephane02[/eluser]
Thanks a lot for your kind helps!!!! It works fine |
Welcome Guest, Not a member yet? Register Sign In |