Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
May 12, 2014

Portion of iRule not being processed

I have combined multiple iRules into one, however the 2nd portion of the rule is not working. I have confirmed using logging that the URI is being caught, however redirection is not taking place. I believe I may not be nesting switch statements correctly.

I have commented which parts of the script are working, and which section is not. Can anyone point me in the right direction?

when HTTP_REQUEST {
    These DO work
   if { ([HTTP::host] equals "olddomain.com") } { 
        switch -glob [HTTP::host] { 
             "/" { HTTP::redirect "http://newdomain.com" } 
             default {  HTTP::redirect "http://newdomain.com[HTTP::uri]" }
        } 
    }
    These do NOT work
   switch -glob [string tolower [HTTP::host]] {
      "oldforum.olddomain.com" {
          Check the URI, set to lowercase
         switch [string tolower [HTTP::query]] {
            "TID=" {
               HTTP::redirect "https://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
               return
            }
            "FID=" {
               HTTP::redirect "https://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
               return
            }
            "C=" {
               HTTP::redirect "https://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
               return
            }
         }
      }
       These DO work
      "*newdomain.com" - "*olddomain.com" {
            switch -glob [string tolower [HTTP::uri]] {
                "/someuri" {
                    HTTP::redirect "http://newdomain.com/path-to/page.aspx"
                    return
                }
                "/someuri2" {
                    HTTP::redirect "http://http://newdomain.com/path-to/page.aspx"
                    return
                }
            }   
        }
    }
}
  • What's being logged is:

     

    Rule test2 : Query is FID=35&title=hhs

     

    It's supposed to be redirecting to:

     

    http://newforum.newdomain.com/default.aspx?g=topics&f=35

     

    However, it's redirecting my browser to:

     

    http://newforum.newdomain.com/default.aspx?g=info&i=4

     

    If I manually change the FID to fid in my browser before making the request - the redirect works. So strange.

     

    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      Sounds like maybe the application itself may be redirecting. The logging statement proves that the proper switch statement is matching. Can you try using Fiddler or HTTPWatch on the client to see if the LTM is responding with the proper redirection and then the server is providing another one?
  • This is incredibly confusing - if I change the switch statement to look like the below - going to this URI with a capital C works....however, now going to this uri with a lowercase c breaks. It used to be the other way around. Something is funky as far as the case.

    "c=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
                   return
                }  
    
    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      Were you able to confirm that when the communications break, that there's another redirect coming back from the server after the LTM does its redirection?
    • Joe_Pipitone's avatar
      Joe_Pipitone
      Icon for Nimbostratus rankNimbostratus
      There's no other redirect that's happening - just checked it with httpwatch and Chrome dev tools. If I reverse the case of the C and c....then it redirects. I currently have this redirection in place using if statements with no issues. I appreciate your help - if there's anything else you may think I'm missing I am all ears! I am going to give this a shot using if statements in the meantime.
    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      It seems like the server would have to be doing the unexpected redirection. I see no other way you'd get redirected to http://newforum.newdomain.com/default.aspx?g=info&i=4 as that's not one of the targets from your iRule. The application sounds like it's behaving unexpectedly (or not) based on the query string. Just out of curiosity, can you post your iRule that works with if{} statements?
  • My other iRule that uses if statements - it is only working with uppercase.

     

    I was able to get everything to work by removing the string tolower, and adding in an additional switch statement for both uppercase and lowercase. I can't explain why this works, but string tolower is not working. Here is the complete code that works now:

     

     Check the Host header value, set to lowercase
       switch -glob [string tolower [HTTP::host]] {
          "oldforum.olddomain.com" {
             switch -glob [HTTP::query] {
                "TID=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
                   return
                }
                "tid=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] tid]"
                   return
                }
                "FID=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
                   return
                }
                "fid=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] fid]"
                   return
                }
                "C=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
                   return
                }
                "c=*" {
                   log local0. "Query string of URI [HTTP::uri] is [URI::query [HTTP::uri]]"
                   HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] c]"
                   return
                }
             }
          }
  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Have you opened a case with F5 Support to get the issue confirmed with an ID?