For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Apr 27, 2015

iRule not catching www.domain.com

The following iRule section where I've indicated "domain1.com" - "domain2.com" {" is not catching the domain1.com with the www. The iRule redirects perfectly fine if I exclude the www. Perhaps the stripping of the www in the beginning of the iRule is conflicting? Can anyone guide me as far as what may be missing? We're on 11.2.1.

when HTTP_REQUEST {
   if { ([HTTP::host] contains "domain1.com") } { 
        switch -glob [HTTP::host] { 
             "/" { HTTP::redirect "http://federalsoup.com" } 
             default {  HTTP::redirect "http://federalsoup.com[HTTP::uri]" }
        } 
    }
   if { ([HTTP::host] eq "www.domain2.com") } { 
        switch -glob [HTTP::host] { 
             "/" { HTTP::redirect "http://domain2.com" } 
             default {  HTTP::redirect "http://domain2.com[HTTP::uri]" }
        } 
    }
    Check the Host header value, set to lowercase
   switch -glob [string tolower [HTTP::host]] {
      "subdomain.domain2.com" {
         switch -glob [HTTP::query] {
            "tid=*" {
               HTTP::redirect "https://domain1.com"
               return
            }
            "fid=*" {
               HTTP::redirect "https://domain2.com"
               return
            }
            "c=*" {
               HTTP::redirect "https://domain3.com"
               return
            }
         }
      }
       This is what's not working - www.domain1.com or www.domain2.com
      "*domain1.com" - "*domain2.com" {
            switch -glob [string tolower [HTTP::uri]] {
                "/2013" {
                    HTTP::redirect "https://domain.com/something"
                    return
                }
                "/2014" {
                    HTTP::redirect "https://domain.com/something1"
                    return
                }
                "/2015" {
                    HTTP::redirect "https://domain.com/something3"
                    return
                }

            }   
        }
    }
}

7 Replies

    • Joe_Pipitone's avatar
      Joe_Pipitone
      Icon for Nimbostratus rankNimbostratus
      If they hit http://www.domain2.com/2015, they're supposed to be redirected to https://domain.com/something3. If a user goes to http://domain2.com/2015, the redirect works fine (without the www)
  • If you are unsure if the domain name is matching place a log statement below it:

     "*domain1.com" - "*domain2.com" {
            log local.0 "[HTTP::Host] has matched *domain1.com or *domain2.com"
            switch -glob [string tolower [HTTP::uri]] {
    

    That will cause the actual value of [HTTP::Host] to be printed to the ltm logs if it matches your domain. You could also put a default into the switch that might offer more detail as to why your host is not matching the wildcard.

  • Sorry, mis-typed the log command. Should be: log local0. "[HTTP::Host] has matched *domain1.com or *domain2.com"

     

    Hope that helps.

     

    • Joe_Pipitone's avatar
      Joe_Pipitone
      Icon for Nimbostratus rankNimbostratus
      I just checked the logs, looks like its complaining about multiple respond/redirect invocations on line 14: TCL error: /Common/my-irule - Operation not supported. Multiple redirect/respond invocations not allowed (line 14) invoked from within "HTTP::redirect "https://forum.domain2.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] fid]"" ("fid=*" arm line 2) invoked from within "switch -glob [HTTP::query] { "tid=*" { HTTP::redirect "https://forum.domain2.com/default.aspx?g=posts&t=[URI::query [HT..." ("subdomain.domain1.com" arm line 2) invoked from within "switch -glob [string tolower [HTTP::host]] { "subdomain.domain1.com" { switch -glob [HTTP::query] { "tid=*" { ..."
    • Joe_Pipitone's avatar
      Joe_Pipitone
      Icon for Nimbostratus rankNimbostratus
      Line 14 starts where it says " Check the Host header value, set to lowercase"
  • I have resolved this - the switch statements were conflicting as in both instances, the domain matched. I've cleaned it up and eliminated what I needed to. I appreciate your help.