Each time it’s time to deploy a CodeIgniter application, I find myself struggling with changing the path in the .htaccess. Therefore; I’m looking for a proper, good working solution which works no matter of the location of the actual project.
Obstacle: My local testing enviroment isn’t localhost/ but rather localhost/project. This won’t, most likely, be the case in the live enviroment (more likely /). Hence, I’d prefer a solution which works anyway.
My current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /project/index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /project/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /project/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /project/index.php
</IfModule>
Using only index.php as a path won’t work. It gives me an 404 not found error.
Have tried a lot of different combinations, and would love to see your suggestions. Thanks!
Personally I dont like your denying of system and application folers in .htaccess.
Per the “best practice on CI” guide found here (http://codeigniter.com/forums/viewthread/125687/) – you should move your application and system folders OUT of public_html, leaving only index.php. Then NO MATTER WHAT fancy stuff people try – they cant access your application & system folders from http.
Then meanwhile – here is my .htaccess file that I use on ALL projects – with no modification required for ANY. It just “works” (for me).
Oh – and I use this for my multiple projects on localhost. i.e. localhost/project1 , localhost/project2
just put a copy of the htaccess file in the root of each project. I DONT have this file in my root localhost