Host re-direct except for directory?

I’ve been trying to use this re-direct to re-direct a main domain e.g. www.oil.com to www.test.com/abc but I dont want www.oil.com/ger to re-direct

Here is what I’ve been trying to use but when I go to www.oil.com/ger its still re-directing

when HTTP_REQUEST { 
    Check if domain is "www.domain.com"
   if {[string tolower [HTTP::host]] eq www.oil.com}{ 
       Check if URI isn't /specialdirectory
       switch [HTTP::uri] { 
         "/ger" { 
             Exit this event from this iRule 
            return
          } 
        } 
   } 
    Redirect everything else to the following 
   HTTP::redirect "http://www.test.com/abc" }

Try this:

when HTTP_REQUEST {
     Check if domain is "www.domain.com"
    if {[string tolower [HTTP::host]] eq "www.oil.com"}{
         Check if URI isn't /specialdirectory
        switch -glob [string tolower [HTTP::uri]] {
           "/ger" -
           "/ger/" -
           "/ger/*" {
                 Exit this event from this iRule
                return
           }
           default {
                 Redirect everything else to the following
                HTTP::redirect "http://www.test.com/abc"
           }
        }
    }
}

Update: Whoops. Shouldn’t try typing fast before I’ve had my coffee. Missed a closed bracket and quotes.

Thanks Joel am getting the following error

line 3: [parse error: PARSE syntax 107 {syntax error in expression “[string tolower [HTTP::host]] eq www.oil.com”: variable references require preceding $}] [{[string tolower [HTTP::host]] eq www.oil.com}]

Put www.oil.com in quotes. And you don’t need the string tolower on HTTP::host.

I’ve updated the rule above.

@Jason: Most browsers will convert the Host: header to lowercase if the user specifies it in mixed or uppercase in the Address bar -- but not all do. And if you look at RFC-2396 (URI specifications), it’s totally silent on case conversion in the authority section of a URI (section 3.2) but explicitly states it in the scheme section (section 3.2)… and then goes on in section 6 (URI normalization) to describe an authority “host” as merely “equivalent” when mixed case but does not _require_ it to be normalized.

Which is why I’ve found plenty of tools that will happily set a Host header with mixed case! Some web-crawlers, for example. Dang “standards”…

I think you’ve still got an extra ] here:

if {[string tolower [HTTP::host]] eq "www.oil.com"]}{

Many thanks Joel I’ve just tested the irule and it works perfectly thanks again for your help.

Pav

Absolutely -- good to hear it’s working for you; glad to help.