CodeIgniter Forums
Codeigniter install on subdirectory (htaccess question) - 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: Codeigniter install on subdirectory (htaccess question) (/thread-52296.html)



Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]Ayeyermaw[/eluser]
I'm not really up to speed on the use of htaccess although I do inderstand it at a base level.
Here's my problem:

I have a top level domain which has a codigniter application. I've removed index.php using htaccess as many people do.

So far so good.

I now want to put separate codeigniter application in a sub folder on that domain. I'm putting a complete codeigniter install in that subdirectory for simplicity and will worry about sharing core files between applications at a later date.
The config file is configured in this second application to use index.php and i have omitted the htaccess file for now. I'll play at removing the index.php later, once this hurdle is out the way.

What I find is that the links on my sub application are showing without the index.php and therefore not working (although the default_controller does load as it should) I assume this is to do with the top level htaccess settings.

I'm probably missing something really simple but have run a search on the forums after attempting to resolve it on my own and come up with nothing.
Any idea how to work around this?







Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]Ayeyermaw[/eluser]
for reference my htaccess file at the top level is as follows:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>




Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]weboap[/eluser]
can you try put an .htaccess in your sub folder install next to index.php and modify the
Code:
RewriteBase /
to be
Code:
RewriteBase /your_subfolder_name/

and use this .htaccess instead.
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /


RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)

RewriteRule ^(.*)$ index.php?/$1 [L]



Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]Ayeyermaw[/eluser]
weboap you're a star mate.
I can't believe i missed the RewriteBase. It should have been obvious

Changing that alone in the subfolder fixed the issue entirely.
I never had to change anything else.
Just out of interest. Is there any specific reason you'd choose your version of .htaccess over mine?




Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]CroNiX[/eluser]
This line is doing nothing (but can cause problems) as the previous 2 lines do the same thing (and cover all cases, while these are specific cases)
Code:
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)



Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]weboap[/eluser]
i usually use the line in question to give access to certain files/directories...

both .htaccess are similar to each other to certain point yours add the protection for /system and application, but in my opinion these 2 folders in production environment shouldn't be in the web folder in the 1st place.
if we consider that public_html is your web root for your project i will use for eg :
Code:
/application
/application2
/system
/public_html
/public_html/index.php
/public_html/.htaccess
/public_html/your_sub_folder/index.php
/public_html/your_sub_folder/.htaccess

in both index.php change the path of system & application accordingly including the name of one of your apps application to application2

if somebody have a better idea. welcome!

hope it help



Codeigniter install on subdirectory (htaccess question) - El Forum - 06-05-2012

[eluser]CroNiX[/eluser]
Then these 2 lines aren't needed
Code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

and you could just use
Code:
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)