CodeIgniter Forums
"Allow from all" entry in .htaccess necessary to load static content - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: "Allow from all" entry in .htaccess necessary to load static content (/thread-44167.html)



"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-05-2011

[eluser]Xoundboy[/eluser]
This is my first post in this forum so I'd like to first say "Hi" to all you good Codeigniter people.

I just downloaded CI 2.02 and have been finding it very simple and straightforward / well implemented. However one thing almost tripped me up....

I placed a link to a js file into one of my views like so:

Code:
<script type="text/javascript" src="<?php echo site_url("application/views/js"); ?>/jquery.flot.js"></script>

... it generates the correct URI for this resource but the js file won't load giving a 403 error: "You don't have permission to access /serverPanel/application/views/js/jquery.flot.js"

The only way I can get it to load is by putting "Allow from all" into an .htaccess file in the root of the views directory. Why is this necessary? It seems wrong to me. Is there some config I need to set somewhere or am I putting my static files in the wrong place?


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-05-2011

[eluser]Aken[/eluser]
Sounds like a file/folder permissions problem. If you're using Apache or a similar hosting service, check the CHMOD values of the various folders in that path, starting with js, then views, working backwards.

Personally I keep Javascript assets away from my application logic as much as possible, so I'd recommend creating your own folder away from the application and system folders for various things like JS, CSS, etc.


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-06-2011

[eluser]Xoundboy[/eluser]
Hi Aken, thanks for your reply.

The first thing I checked were the permissions but all folders in the path have 755 so its definitely not a permission problem. It must be something else but I'm not sure what to look for.

Anyway, I took your advice and moved my css and js out of the views folder and put them into application/static/ which seems like a suitable place - and of course moved the 'Allow from all' .htaccess file into there too.


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-06-2011

[eluser]MiniGod[/eluser]
Loading a file directly from the view or even application folder is not recommended.

You should move them out of the application folder. Assets/Static files should be in its own directory.
If you use mod_rewrite, remember to add the directory to the .htaccess file.


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-06-2011

[eluser]idealws[/eluser]
Hello,

I use the following structure if it helps you:

public_html
-assets
-images
-css
-js
-index.php
-.htaccess
system
-application
-core

You can then change your above code to:

Code:
<?php echo site_url(); ?>assets/js/jquery.flot.js

Hope this helps. I don't like putting the core and application files in the public_html or www folder. I feel it is more secure moving them down a directory off the public view.


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-07-2011

[eluser]Xoundboy[/eluser]
[quote author="idealws" date="1312679586"]

I use the following structure if it helps you:

public_html
-assets
-images
-css
-js
-index.php
-.htaccess
system
-application
-core
[/quote]


... thanks for this... I re-arranged mine like this and it seems much better organised - plus it works without the .htaccess file


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-07-2011

[eluser]CodeIgniteMe[/eluser]
I suggest using base_url() instead of site_url() for portablity, because site_url() will include the base url and the index.php (if you set one) in your config file.
and the reason why you can't include the files from your views is because there is a .htaccess file in the application directories which prevents anything from being "hacked" into those inside the application directories.
you can have your own js, css, images, and downloads directory outside the application and system folders, but I still recommend to put them inside a common folder, like idealws did.


"Allow from all" entry in .htaccess necessary to load static content - El Forum - 08-07-2011

[eluser]okbang[/eluser]
There are many of favor combined with decent summer and spring luggage you can find, you can easlily determine your own just one particular and have a nice summer months

As we know, trend setting dance shoes are necessary toward young women and / or mothers across the country. Towards woman, bags just can't one assist have a loads of regularly content material that include facelift skin, natural skin care merchandise, mobile phones and so forth ., but also help you and your family prove to the fashion seem. Straight away, the fabric totes are certainly loved by a whole lot of styles young females due to the fact style of material can display the main different noble atmosphere. Here in the summer, additionally it is usual for females to attend a handful of individuals or groups, subsequently a way artificial leather carrier is quite a necessity. And after this, I would like to have an outstanding summer season bags against you.