CodeIgniter php framework: js and css files inside "application" folder. How to do? - .htaccess

I just installed the php framework CodeIgniter 3 and it seems that JS,CSS and images should be placed OUTSIDE Application folder. If not, link to those files inside views does not run.
For many reasons I would like to have these kind of files inside application/views folder. I think that I should correctly set .htaccess file, but I would also like to "lower my defenses less possible", so give only strict necessary privileges.
How to do it?
Thank you.

Do like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|assets|js|images|css|robots\.txt)
RewriteRule ^(.*)$ /your_ci_folder/index.php/$1 [L]

Related

CodeIgniter: js and css files inside "application" folder. How to do?

I just installed CodeIgniter 3 and it seems that JS,CSS and images should be placed OUTSIDE Application folder. If not, link to those files does not run.
For many reasons I would like to have these kind of files inside application/views folder. I think that I should correctly set .htaccess file, but I would also like to "lower my defenses less possible".
What do you suggest?
All you need to do is in the application folder .htaccss change deny all to allow all and then make sure you auto load url helper and the call your folder from where ever you want.
Update you could try this code in application/.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|assets/css|assets/js|assets/ficheros|assets/img|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
rename assets folder to what you want if using xampp/wampp etc do not for get to stop and then restart it. Of course when paste code do not for get to remove the deny all.
Its simple, just delete the contens inside the .htaccess file. It worked for me.

Installing codeigniter in a subfolder and point to the main site?

I'm trying install my codeigniter application in a sub folder: http://website.com/sub_folder
And I want that this site is accessible through: http://website.com/
I have the following info in my application/config.php file for the base url: $config['base_url'] = 'http://website.com/sub_folder';
This is my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|assets|favicon\.gif|robots\.txt)
RewriteRule ^(.*)$ /sub_folder/index.php/$1 [L]
The problem is that when I change the $config['base_url'] to access my asset files, like css etc al my other links using $base_url() point to : http://website.com/sub_folder too instead of http://website.com/
If I understand what you want to achieve, you're doing it wrong, simply place index.php file in your root folder and your application to the sub-folder.
Change system and application paths in index.php to where exactly they are located and you're done.
$system_path = 'subfolder/system';
$application_folder = 'subfolder/applications';
In any case, if it's possible, consider moving application and system folders out of the root directory as it will cover hundreds of potential security holes.

CodeIgniter Path Issue

I am use Codeigniter to creat my site. it is a huge site with a lot of contents.
i use the default welcome controller for all pages.
the path is like this now
http://mydomain.com/index.php/welcome
and my folder structure is like this
/root
/codeigniter Application folder
/controller
/view
/static/
/images/
/css/
/pdf/
.htaccess
because i am doing the content first, so all the images are set to absolute patch (http://mydomain.com/static/images/foldername/pc.jpg)
now when i use the rewrite to remove "inde.php" and "welcome"
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
all css and image file are not accessible anymore. I have nearly a thousand pages with images. I don't have the time to change the page one by one. the deadline is coming, please help.
thanks
Have you tried adding the css-folder to your excluded rewriteconditions?
RewriteCond $1 !^(index\.php|images|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Does not seem to exclude the folder css from rewriting (see images is excluded).
Try something like
RewriteCond $1 !^(index\.php|images|css|robots\.txt|system|pdf|sitemap\.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*)\.pdf|phpadmin)
Good luck
I think the problem lies with your .htaccess file. We have a similar setup, and that url living outside of the application directory is available just as you have it with a direct url relative to its path. Check out the wiki at http://codeigniter.com/wiki/mod_rewrite for the correct way to set up your .htaccess file.
Edit to clarify: The url http://mydomain.com/static/images/foldername/pc.jpg should work. something about your .htaccess file is wrong.
RewriteCond $1 !^(static|index.php|images|robots.txt|system|pdf|sitemap.xml|profile.htm|^([A-z,0-9,_,-]+).asp|(.*).pdf|phpadmin)

Expression Engine - template page not showing

I have two pages on a site that I just completed that are no longer showing. I am running EE 2.2.2 and use .htaccess to hide the index page.
There are several templates in the same directory, all but two of them show correctly. For example:
This shows correctly: http://southernlivingplants.com/landscape
While these two do not:
http://southernlivingplants.com/grower
http://southernlivingplants.com/retailer
I get the following error message:
Index of /retailer
Parent Directory
Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2
mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server
at southernlivingplants.com Port 80
The problem I see is that neither /retailer or /grower are directories.
Here is the htaccess code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
I would appreciate some help in figuring this out.
Alas, user error. Someone else had created folders of the same name, which were in conflict with the template names.
If I put index.php in the URL the pages seem to come up, so it's probably an .htaccess issue. Have you been through the official docs for removing it? There's several options: http://expressionengine.com/user_guide/general/remove_index.php.html
Another idea...you said that retailer and grower are all in the same directory? EE doesn't generally work like that unless you're using Structure. Template groups define new top level directories and each template inside is a sub directory (other than the index). So in this case if they're all in the landscaping directory the urls' would be /landscaping/retailer and /landscaping/grower. Hope that helps!
It looks like you are using the "File and Directory Check" method for the .htaccess file for ExpressionEngine.
Are retailer and grower template groups or templates in EE?
Have you tried removing the ? after the index.php in the rewrite rule? What hosting company are you using?
I have had best success with the "Exclude" method myself.
http://expressionengine.com/wiki/Remove_index.php_From_URLs#Exclude_List_Method
You essentially put in the ReWriteCond the folders / files that you do NOT want EE to parse as if it's a template. So, your /images, /system, /themes, etc directories, if you end up having one for /js or another application, you just add them to that line. (Make sure to escape the periods.) I suggest trying that method. That way everything else will definitely go through EE.

Use htaccess to mask folder name

Here's a problem I'm always wanting to solve with htaccess. I haven't found a way yet, though it looks like it should be possible - perhaps someone can help.
Let's say I have a folder at the root of my site called /foo/. I want users to be able to access that folder at the path /bar/, but for various reasons I can't rename the folder.
So as not to create confusion I only want one path to ever be seen - that is to say, I don't want people to use the name /foo/ to access the folder; they should always use /bar/. If someone goes to example.com/foo/, their browser should redirect to example.com/bar/ - but the content returned should be the content of /foo/.
To make matters more complicated, pages in /foo/ have dependencies (images, stylesheets, links to other pages, etc) within /foo/ which are hardcoded and can't be changed. These must, of course, still work.
So, to summarise, this is what I want :
Requests for example.com/foo/ should redirect to example.com/bar/.
Requests for example.com/bar/ should return the contents of example.com/foo/.
Is this possible? It looks on the surface as if it would create an infinite redirect... but I'm pretty sure there are ways to prevent that in htaccess, aren't there?
I'd be very grateful for any help.
(PS - for a little extra background: The normal reason I want to do this is to rename the wordpress /wp-admin/ directory to something more professional and easy for customers to remember, such as /admin/. But the same system should work for masking any path in this way.)
I found a sort of workaround - by using a symlink and htaccess in combination.
First I created a symlink from /bar to /foo/.
Then I put this in htaccess :
Options +FollowSymLinks
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
This has exactly the desired result - example.com/bar/ shows the content of the /foo/ directory, and example.com/foo/ redirects to example.com/bar/
But if anyone can come up with a pure htaccess solution I'd much prefer that!
Update :
Ok, I've finally found out how to do this. It turns out to be quite simple...
RewriteCond %{THE_REQUEST} ^GET\ /foo/
RewriteRule ^foo/(.*)$ bar/$1 [R,L]
RewriteRule ^bar/(.*)$ foo/$1
The only problem is that it doesn't take account of RewriteBase, so you have to include the full path in the first line (after ^GET\).
If I understand correctly what you want is something like this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^foo/$ bar/
RewriteRule ^bar/$ foo/
</IfModule>

Resources