views:

40

answers:

2

I have two .htaccess files that I need to combine into one.

The first one does a simple file extension remover.

The second one rewrites all requests to go to a third party app, keeping our URL.

What I need is to have the rules be smart enough to not look at the second server if the file exists on the first.

Rule1 :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Rule 2:

Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteRule ^(.*)$ http://third.party.com/$1 [P]
# RewriteCond %{THE_REQUEST}([^?\ ]+) 
# RewriteRule ^.*$ index.php/%1

I'm far from an .htaccess wizard, so I'm all ears for suggestions.

A: 

You can add the L flag to stop rewriting at a given rule. For example:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^(.*)$ http://third.party.com/$1 [P]
# RewriteCond %{THE_REQUEST}([^?\ ]+) 
# RewriteRule ^.*$ index.php/%1

See the mod_rewrite docs (search for "Stop the rewriting process").

Max Shawabkeh
A: 

So do you want one rule to work for one site and another one for the other? If yes, you can use RewriteCond %{HTTP_HOST} directives to limit their scope.

TonyCool