Best Practices for Negative Condition Check

Topics: Developer Forum, User Forum
Apr 28, 2010 at 10:08 PM
Hello all: I have a set of two rules that I need to check against, and its basically a NOT condition but I'm struggling to get it right. This is what I need to do: If the page request coming in does NOT contain the folder "eCommerce" and does NOT contain "Login.aspx" (case insensitive for both check) redirect to an under construction page. So if the request is ...continue on So if the request is continue on Anything redirected, so its a negative check against full url path: if doesn't contain x and doesn't contain y then redirect, and I can't seem to get it right. Any ideas? Thanks in advance
Apr 29, 2010 at 1:12 AM

OK here is where I am stuck, do I need to break this up into multiple statements? I need a negative look ahead

For example:

RewriteCond %{HTTP_HOST} ^$
#Redirect any request not pointing to Login.aspx OR SSO folder OR HtmlPages Folder
RedirectRule ^/(?!(SSO|HTMLPages))([^/]+)/(.*)$ [I]

So if coming from the domain step one...

After this I need to check

If the Request is DOES NOT...

contain Login.aspx,

contain the SSO Folder,

contain the HTMLPages folder

Then redirect.

In my example above, I am not accounting for the Login.aspx check, but I am still winding up in an endless loop...and I understand why, its the logical OR, but I'm having a hard time fixing it.


Apr 29, 2010 at 7:56 AM

In your case you may want to flip your logic and write rules that say, DO NOT rewrite when the URL match.

like this:

## These are keepers: 
RewriteRule HTMLPages    -  [L]
RewriteRule Login\.aspx  -  [L]
RewriteRule SSO          -  [L]

## Otherwise, under construction:
RedirectRule   .*