.htaccess issues

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

Post 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]
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess issues

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: .htaccess issues

Post by Eran »

Rewrite base should match the directory -

Code: Select all

RewriteBase /admin/
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess issues

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: .htaccess issues

Post 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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess issues

Post 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]
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: .htaccess issues

Post by Eran »

you didn't add the path to the admin index.php
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: .htaccess issues

Post by alex.barylski »

Bingo! :D

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