Forum Discussion

Gary_Bristol_19's avatar
Gary_Bristol_19
Icon for Nimbostratus rankNimbostratus
Jul 29, 2015

need to check for a path in an irule

i need to check for a path in an irule if it isn't there send it to one re-direct if it is, send it to a different re-direct

 

when HTTP_REQUEST {

 

set lhost [string tolower [HTTP::host]] set lpath [string tolower [HTTP::path]]

 

if { $lhost equals "itservices.ou.edu" } { if { not ($lpath starts_with "/norman") }{ HTTP::redirect "https://ouitservices.service-now.com/ess_portal" } } elseif { $lhost equals "itservices.ou.edu" } { if { ($lpath starts_with "/norman") }{ HTTP::redirect "http://itscnorman.ou.edu" } } }

 

2 Replies

  • Is your code not working for you? I will say that it can be somewhat simplified, since your outside if/else conditionals check the same condition and the inner [if]s are negations of one another:

     

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "itservices.ou.edu" } {
            if { [string tolower [HTTP::path]] starts_with "/norman" } {
                HTTP::redirect "https://ouitservices.service-now.com/ess_portal"
            } else {
                HTTP::redirect "http://itscnorman.ou.edu"
            }
        }
    }
    

     

    If you are running at least version 11.4, you should be able to accomplish this with a Local Traffic Policy, as well:

    A Local Traffic Policy should, in general, be more performant, and is integrated with the web UI and CLI.