Forum Discussion

Gary_Bristol_19's avatar
Gary_Bristol_19
Icon for Nimbostratus rankNimbostratus
Dec 15, 2015

additional conditions on an irule

i have an iRule that does a check for a home page if it matches then send it to a specific pool. then i check a External Data Group list for redirection and pool selections or a default pool for none matches. the problem i have now is that not all fall through URL's are defined in the EDG list. but i also need the ou.edu/ match to re-direct to the www.ou.edu/. but ou.edu/something will also match that last entry and as such will not fall through.. here is my current iRule, thanks to the answeres here.

when HTTP_REQUEST {
  Lookup the redirect or pool based upon match_string value
  set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
  if { [string tolower [HTTP::host][HTTP::path]] equals "www.ou.edu/" }{
    pool www_ou_edu_cms_servers
  } else {
    switch [getfield $goto "," 1] {
      "pool" { pool [getfield $goto "," 2] }
      "redir" { HTTP::redirect [getfield $goto "," 2] }
      default { pool ouwww_bostitch }
    }
  }
}

Here is what has been suggested as a replacement ..

when HTTP_REQUEST {
  Lookup the redirect or pool based upon match_string value
  if { ([string tolower [HTTP::host]] equals "ou.edu") and ([string tolower [HTTP::path]] equals "/") }{
    HTTP::redirect "http://www.ou.edu/"
  } else {
    set host [string tolower "www.[HTTP::host][HTTP::path]"]
  }
   set host [string tolower "www.[HTTP::host][HTTP::path]"]
  set goto [class match -value $host starts_with www_ou_edu_redir_class]
  if { [string tolower [HTTP::host][HTTP::path]] equals "www.ou.edu/" }{
    pool www_ou_edu_cms_servers
  } else {
    switch [getfield $goto "," 1] {
      "pool" { pool [getfield $goto "," 2] }
      "redir" { HTTP::redirect [getfield $goto "," 2] }
      default { pool ouwww_bostitch }
    }
  }
}

9 Replies

  • This seems to work but is not as Eloquent as what has been provided from here..

    when HTTP_REQUEST {
      Lookup the redirect or pool based upon match_string value
          if { [string tolower [HTTP::host][HTTP::path]] equals "ou.edu/" }{
      HTTP::redirect "http://www.ou.edu/"
        }
      set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
        if { [string tolower [HTTP::host][HTTP::path]] equals "www.ou.edu/" }{
        pool www_ou_edu_cms_servers
      } else {
        switch [getfield $goto "," 1] {
          "pool" { pool [getfield $goto "," 2] }
          "redir" { HTTP::redirect [getfield $goto "," 2] }
          default { pool ouwww_bostitch }
        }
      }
    }
    
    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      Hi Gary, I don't get the purpose of "pool ouwww_bostitch" and "pool www_ou_edu_cms_servers". Please explain which URLs (host/path) should be routed to those pools. Specify some wildcards if needed... Cheers, Kai
    • Gary_Bristol_19's avatar
      Gary_Bristol_19
      Icon for Nimbostratus rankNimbostratus
      Those pools are where the content resides for specific web pages as defined in an External Data Group File. So the CMS Pool is where the centrally managed University web site lives but the Bostitch is where the Faculty staff web sites live. so depending on the url they would be directed to the specific pool or redirected to a different url, but there are some default actions that need to happen which is why there are the different conditions.
    • Gary_Bristol_19's avatar
      Gary_Bristol_19
      Icon for Nimbostratus rankNimbostratus
      For instance here are some sampe entries www.parking.ou.edu := "redir,http://www.ou.edu/parking.html", www.outreach.ou.edu := "redir,http://www.ou.edu/outreach.html", www.oubc.ou.edu := "redir,http://www.ou.edu/coe/bioengineering/home.html", www.ou.edu/ymvw := "pool,www_ou_edu_cms_servers", www.ou.edu/writingcenter := "pool,www_ou_edu_cms_servers", www.ou.edu/writing := "pool,www_ou_edu_cms_servers", www.ou.edu/wpge := "redir,http://wpge25.wix.com/wpge", tour.ou.edu := "redir,http://www.ou.edu/go2/visit.html", tinker.ou.edu := "redir,http://www.ou.edu/cls/ou_tinker.html", thecore.ou.edu := "redir,http://www.ou.edu/thecore", theatre.ou.edu := "redir,http://www.ou.edu/content/finearts/universitytheatre.html", techhelp.ou.edu := "redir,http://www.ou.edu/content/ouit/help/personal.html", teachin.ou.edu := "redir,http://www.ou.edu/publicaffairs/teachin.html", teach.ou.edu := "redir,http://www.ou.edu/cte", tcom.ou.edu := "redir,http://www.ou.edu/coe/tcom", tao.ou.edu := "redir,http://www.ou.edu/cte/tao/", annualreport.ou.edu := "redir,http://www.ou.edu/web/about_ou/communityimpactreport", ame.ou.edu := "redir,http://www.ou.edu/coe/ame/home.html", alumni.ou.edu := "redir,http://www.ou.edu/alumni", alumni.coa.ou.edu := "redir,http://www.ou.edu/content/architecture/aud/alumni_friends.html", alerts.ou.edu := "redir,http://www.ou.edu/ouit/help/alerts", alc.ou.edu := "redir,http://www.ou.edu/univcoll/alc", airport.ou.edu := "redir,http://www.ou.edu/airport.html", ou.edu/home := "pool,www_ou_edu_cms_servers", ou.edu/healthservices := "pool,www_ou_edu_cms_servers", ou.edu/healthcareoptions := "pool,ouwww_bostitch", ou.edu/harps := "pool,www_ou_edu_cms_servers", ou.edu/gradweb := "pool,www_ou_edu_cms_servers",
  • Hi Gary,

    its indeed not an easy task without changing the entire data group structure... 😉

    The script below is the best I can do for you...

    when HTTP_REQUEST {
        set low_host_path [string tolower [HTTP::host][HTTP::path]
        if { $low_host_path equals "ou.edu/" } then {
            HTTP::redirect "http://www.ou.edu/"
        } elseif { $low_host_path equals "www.ou.edu/" } then {
            pool www_ou_edu_cms_servers
        } else {
            Lookup the redirect or pool based upon match_string value
            set goto [class match -value $low_host_path starts_with www_ou_edu_redir_class]
            switch -exact -- [getfield $goto "," 1] {
                "pool" { pool [getfield $goto "," 2] }
                "redir" { HTTP::redirect [getfield $goto "," 2] }
                default { pool ouwww_bostitch }
            }
        }
    }
    

    Cheers, Kai

  • actually i don't think i want the switch -exact on the settting as i have many pool selections that depend on going to a content pool of servers below a certain directory level. I do have some that are more specific that need to go to different places that is why i do a reverse sort on the EDG file.

    here is what i was able to come up with..

    when HTTP_REQUEST {
      Lookup the redirect or pool based upon match_string value
       set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
       if { [string tolower [HTTP::host][HTTP::path]] equals "ou.edu/" }{
            HTTP::redirect "http://www.ou.edu/"
      } elseif { [string tolower [HTTP::host][HTTP::path]] equals "www.ou.edu/" }{
            pool www_ou_edu_cms_servers
      } else {
        switch [getfield $goto "," 1] {
          "pool" { pool [getfield $goto "," 2] }
          "redir" { HTTP::redirect [getfield $goto "," 2] }
          default { pool ouwww_bostitch }
        }
      }
    }
    
    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      The -exact is actually the default value of the [switch] command. I tend to specify this explicitly to avoid confusion. In addition the -exact match would only be used to match the string "pool" or "redir" (aka. [getfield $goto "," 1]) and then fall back to "default". The reson why I'm using the $low_host_path variable is pure performance releated. My example calculates a single time the string "[string tolower [HTTP::host][HTTP::path]]" and your example multiple times. I've moved the [set goto] command into the } else { statement to optimize processing. If the upper redirects are triggering the class command wouln't be executed in this case... So in the end a lot of "hidden" optimizations you shouldn't skip ;-) Cheers, Kai
  • ok this is what i ended up with...

    when HTTP_REQUEST {
      set the variable with the host and path value
       set low_host_path [string tolower [HTTP::host][HTTP::path]]
        check for ou.edu/
        if { $low_host_path equals "ou.edu/" }{
            HTTP::redirect "http://www.ou.edu/"
         check for www.ou.edu/
      } elseif { $low_host_path equals "www.ou.edu/" }{
            pool www_ou_edu_cms_servers
      } else {
        Lookup the redirect or pool based upon match_string value
        set goto [class match -value $low_host_path starts_with www_ou_edu_redir_class]
        switch [getfield $goto "," 1] {
          "pool" { pool [getfield $goto "," 2] }
          "redir" { HTTP::redirect [getfield $goto "," 2] }
          default { pool ouwww_bostitch }
        }
      }
    }