Forum Discussion

pchace's avatar
pchace
Icon for Nimbostratus rankNimbostratus
Aug 09, 2019

Trying to replace the header host value if it doesn't match 2 conditions

I am trying to write an irule that will replace the header host value if it does not meet 1 given value or a 2nd given value. I tried the below irule based on info I gathered from various posts but it does not like the syntax. I am using version 13.1.1.2

 

when HTTP_REQUEST { 

  if { ([HTTP::header host] not "abc.host.com") or \

     ([HTTP::header host] not "xyz.host.com") } { 

    HTTP::header replace Host "abc.host.com" 

  } 

 }

 

If I try to save the above rule, I get this error: 01070151:3: Rule [/Common/rule_abc_host_header_replace] error: /Common/rule_abc_host_header_replace:2: error: [parse error: PARSE syntax 51 syntax\ error\ in\ expression\ \"\ (\[HTTP::header\ host\]\ not\ \"abc.host.com\")\ or\ \\\n\ \ \ \ \ \ \ \ \ (...\":\ looking\ for\ close\ parenthesis][{ ([HTTP::header host] not "abc.host.com") or \

([HTTP::header host] not "xyz.host.com") }]

10 Replies

  • Wouldn't this work as a Local Traffic Policy configured like this?:

    • pchace's avatar
      pchace
      Icon for Nimbostratus rankNimbostratus

      I am so accustomed to using irules for everything and I am not real familiar with Local Traffic Policy. However this looks like it will do what I need. I will test it and let you know. Thanks!

      • DanS92's avatar
        DanS92
        Icon for Cirrus rankCirrus

        I am too... But I’ve spent a good amount of time over the last year converting everything I can from iRules to Local Traffic Policies. Especially iRules that direct certain traffic to certain pools based on hostname, because it shows up much better on the Network Map.

  • Try:

    set HOST [string tolower [HTTP::host]]
    if { (not ($HOST eq "abc.host.com")) or
         (not ($HOST eq "xyz.host.com")) } {
    • pchace's avatar
      pchace
      Icon for Nimbostratus rankNimbostratus

      Thanks Vijay,

      Let me know if I did something wrong, but I entered the rule like this:

      when HTTP_REQUEST {

      HOST = [string tolower [HTTP::host]]

      if { (not ($HOST eq "abc.host.com")) or

         (not ($HOST eq "xyz.host.com")) } {

          HTTP::header replace Host "abc.host.com" 

        } 

       }

       

      And it gave me this error: 01070151:3: Rule [/Common/rule_header_replace_abc] error: /Common/rule_header_replace_abc:2: error: [undefined procedure: HOST][HOST = [string tolower [HTTP::host]]]

  • Sorry, edited the previous code snippet. "set" should be used for variable creation.

    • pchace's avatar
      pchace
      Icon for Nimbostratus rankNimbostratus

      Oh right, I should have know that as well. However it still does not work as it does not like something in the syntax. Also I am not triggering it based on the host. The item that is supposed to trigger the event is if the http header does not have a specific hostname in the header.

      • Vijay_E's avatar
        Vijay_E
        Icon for Cirrus rankCirrus

        So, it isn't working but no error ? If so, have you tried using log local0 for logging ?