Page 1 of 1

.htaccess issues

Posted: Sun Jul 26, 2009 5:11 pm
by alex.barylski
I have two .htaccess files

1 in the root document that accepts request for the front end application and another in the subdirectory 'admin' the former is conflicting with the 'admin' version I believe, how do I prevent/block the directory 'admin' from being interpreted by the root .htaccess?

root example:

Code: Select all

RewriteEngine on
RewriteBase /
 
SetEnv TEXO_WWW_DEFAULT "www"
 
# Redirect access to non-www to www version -- apache have virtual host mappings for both non-www and www for this to work as expected
RewriteCond %{HTTP_HOST} ^demosite.com [NC]
RewriteRule ^(.*)$ http://www.demosite.com/$1 [L,R=301]
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
 
RewriteRule ^(.*)$ index.php [QSA,NC,L]
admin example:

Code: Select all

RewriteEngine on
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
 
RewriteRule ^(.*)$ [QSA,NC,L]

Re: .htaccess issues

Posted: Sun Jul 26, 2009 5:14 pm
by alex.barylski
I have tried adding this snippet borrowed from Drupal:

Code: Select all

RewriteCond %{REQUEST_URI} "/admin/"
RewriteRule (.*) $1 [L]
Didn't work obviously :(

EDIT | Whats actually happening is that the root .htaccess is accepting requests for everything, like I want it too (except for existing files/folders). I can access the 'admin' directory as expected but whenever I access something in the admin, it's the root .htaccess thats delivering the request, which is not what I need.

I need the .htaccess in the 'admin' directory to deliver all sub-requests to it's index.php not the root version.

Cheers,
Alex

Re: .htaccess issues

Posted: Sun Jul 26, 2009 5:22 pm
by Eran
Rewrite base should match the directory -

Code: Select all

RewriteBase /admin/

Re: .htaccess issues

Posted: Sun Jul 26, 2009 6:10 pm
by alex.barylski
Thanks man, but I'm totally clueless when it comes to .htaccess crap. :P :oops:

I added that to the root .htaccess but when I access a URI like:

Code: Select all

demosite.com/admin/user/login
Still the root index.php is what handles the request.

Only this works:

Code: Select all

demosite.com/admin/
In this case the proper admin/index.php is invoked but I need it so anything under admin is handled by index.php except files that already exists like images, etc

Re: .htaccess issues

Posted: Sun Jul 26, 2009 6:14 pm
by Eran
just noticed you are missing the index.php directive in your admin htaccess. They way it works, those files stack over each other, and since you aren't overriding the original one it goes to the same index.php.
In your admin htaccess direct it to:

Code: Select all

RewriteRule ^(.*)$ /path/to/admin/index.php ...
I think that would do it

Re: .htaccess issues

Posted: Sun Jul 26, 2009 6:21 pm
by alex.barylski
Negative...

Here they are in their current form:

root:

Code: Select all

RewriteEngine on
RewriteBase /
 
SetEnv WWW_DEFAULT "www"
 
RewriteCond %{HTTP_HOST} ^demosite.com [NC]
RewriteRule ^(.*)$ http://www.demosite.com/$1 [L,R=301]
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
 
RewriteRule ^(.*)$ index.php [QSA,NC,L]
admin:

Code: Select all

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

Re: .htaccess issues

Posted: Sun Jul 26, 2009 6:34 pm
by Eran
you didn't add the path to the admin index.php

Re: .htaccess issues

Posted: Sun Jul 26, 2009 6:50 pm
by alex.barylski
Bingo! :D

That seems to have done the trick, thank you very much, that was driving me insane. :)