Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite AND

satisfy multiple conditions

         

WhosAWhata

5:15 am on Apr 1, 2004 (gmt 0)

10+ Year Member



if i want a rewrite to occur only if 2 conditions are satified

ex:

RewriteCond %{REQUEST_URI}!^.*/index\.php$ AND %{REQUEST_URI}!(*.)/$  
RewriteRule (.*) index.php?page=$1 [L]

or do you say something like

RewriteCond %{REQUEST_URI}!^.*/index\.php$ 
RewriteCond %{REQUEST_URI}!(*.)/$
RewriteRule (.*) index.php?page=$1 [L]

basically do you have two RewriteCond's, or do you have one with an AND symbol

jdMorgan

5:41 am on Apr 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are several ways to do it. Given your requirement of a negative match on both of two URLs:

RewriteCond %{REQUEST_URI} !^(URL1¦URL2)
RewriteRule...

-or-

RewriteCond %{REQUEST_URI} !^URL1$
RewriteCond %{REQUEST_URI} !^URL2$
RewriteRule ...

The first method is based on the fact that NOT(A OR B) is equivalent to (NOT A) AND (NOT B); See DeMorgan's Theorem for proof. Also, remember to change the broken vertical pipe "¦" character to a solid vertical pipe character before using this code.

The second method shown is the more straighforward approach and demonstrates the default 'AND' behaviour of RewriteConds in the absense of the optional [OR] flag. There is no explicit AND operator, however.

Jim

WhosAWhata

5:44 am on Apr 1, 2004 (gmt 0)

10+ Year Member



thanks jim, just what i needed

WhosAWhata

6:00 am on Apr 1, 2004 (gmt 0)

10+ Year Member



by the way, this is very irrelivent, but why does webmaster world change the broken/unbroken pipes?