Reputation: 2800
I am not able to access the files(images, css) inside my application and root folder of codeigniter. I have checked the permissions and the links. Everything seems to be fine but it gives a 404 error when trying to load the file. I even tried to load the link directly. All files seems to be loading from the assets but not from the root or application folder.
.htaccess file :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I am not sure what direction to look in. As a matter of fact they were working fine few days back, I haven't made any changes in the htaccess file. Any help wil be appreciated. Thanks.
Upvotes: 0
Views: 2052
Reputation: 763
One of the more common setups would be having it all like this:
Filestructure:
/docroot
- /assets
+ /css
+ /js
+ /img
+ application
+ system
* .htaccess
* index.php
.htaccess (v1):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
or the more flexible way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
and now in your markup you gotta load:
<link rel="stylesheet" href="/assets/css/whatever.css"></link>
<script src="/assets/js/bla.js"></script>
<img src="/assets/img/logo.png" alt="Nice Logo">
As for files not being accessible within the application folder, that's due to a .htaccess file in that folder denying all access in general. To prevent unintended file exposal.
And if you want to access files directly in the docroot, you would have to change to the second .htaccess version
Upvotes: 2