Volomike
Volomike

Reputation: 24886

Can I combine these two .htaccess files into one?

It is possible to combine these two .htaccess files into one? They deal with two separate PHP apps that have completely separate pretty URL handling. The reason why I want to try one is because mod_security is throwing errors and completely ignoring my second .htaccess file in the chain here, but seems to not have a problem with one .htaccess file.

So, if one goes to /blah, the first app handles the pretty URL handling. But if one goes to /members/blah, the second app handles the pretty URL handling. However, note the -f and -d parameters where we check for actual file or directory paths and permit those through.

In the root:

RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^members$ /members/ [QSA,L]
RewriteRule ^members/(.*)$ /memberapp/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

In /memberapp:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /memberapp/index.php [QSA]

EDIT 1:

So, here's the mapping example:

domain.com = domain.com/index.php
domain.com/ = domain.com/index.php
domain.com/?test=test = domain.com/index.php
domain.com/members/test.png = domain.com/memberapp/test.png (file exists)
domain.com/members/dir1 = domain.com/memberapp/dir1 (directory exists)
domain.com/members/dir1/ = domain.com/memberapp/dir1 (ditto)
domain.com/test = domain.com/index.php
domain.com/members/login = domain.com/memberapp/index.php
domain.com/members/test.php = domain.com/memberapp/test.php (file exists)
domain.com/dir1 = domain.com/dir1 (directory exists)
domain.com/dir1/ = domain.com/dir1 (directory exists)
domain.com/test.png = domain.com/test.png (file exists)
domain.com/members/login?test=test = domain.com/memberapp/index.php

Upvotes: 0

Views: 346

Answers (1)

Gerben
Gerben

Reputation: 16825

RewriteEngine On

RewriteRule ^index\.php$ - [L]
RewriteRule ^members$ /members/ [R=302,L]
RewriteRule ^members/(.*)$ /memberapp/$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^membersapp/ /memberapp/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Upvotes: 1

Related Questions