.htaccess issues with sub-directory applications

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

.htaccess issues with sub-directory applications

Post by alex.barylski »

I alwasy run into this issue and can never find my old threads...personal KBASE me thinks :)

ANyways I have index.php in my root directory looks something like:

Code: Select all

RewriteEngine on
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,NC,L]
One of the sub-directories is 'admin' which houses various applications which also need to use .htaccess but their own so as to be compartmenaltized (I should be able to drop in an admin application not have to notify the .htaccess in root to forward requests for directory 'admin/something' to it's index.php file.

So the structure lookes like

Code: Select all

index.php
.htaccess
admin
admin/forum/.htaccess
admin/forum/index.php
Unfortunately the later doesn't seem to want to work as the root index.php is being invoked and looking for a resource which doesn't exist.

Anyway around this issue, considering the drop in requirements?

Cheers,
Alex
Virvo
Forum Newbie
Posts: 3
Joined: Wed Nov 25, 2009 4:20 am

Re: .htaccess issues with sub-directory applications

Post by Virvo »

Change your ROOT .htaccess to:


RewriteCond %{REQUEST_URI} !^admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,NC,L]

this says... if the URI doesnt start with 'admin' ... go to index.php, otherwise go to the admin folder and process the request as normal (at which point your admin directory .htaccess would take over)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess issues with sub-directory applications

Post by alex.barylski »

this says... if the URI doesnt start with 'admin' ... go to index.php, otherwise go to the admin folder and process the request as normal (at which point your admin directory .htaccess would take over)
EDIT | I tried this but still doesn't work:

Code: Select all

http://www.pcspectra.com/admin/system/a ... /.htaccess
 
RewriteEngine on
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,NC,L]

Code: Select all

http://www.pcspectra.com/.htaccess
 
RewriteEngine on
RewriteBase /
 
RewriteCond %{HTTP_HOST} ^pcspectra.com [NC]
RewriteRule ^(.*)$ http://www.pcspectra.com/$1 [L,R=301]
 
RewriteCond %{REQUEST_URI} !^admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,NC,L]
Any ideas?

Cheers,
Alex
Post Reply