Forum Discussion

Anthony_Fornito's avatar
Nov 22, 2017

regex HTTP::header replace "Host"

I am trying to create an irule that can use a regex like:

/^([\s\S]?)(domain.com)./g

So if a user types:

domainname.com

abc.domainname.com

abc.domainname.com\xyz

It will still work.

Current irule

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri] ] contains "/?node=1" } {
    HTTP::header replace "Host" "dev.domainname.com"
    HTTP::path "/"
    node 192.168.70.57 443
  }
}

I have tried to put the irule in line but it keeps giving errors and google is no help at all.

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri] ] contains "/?node=1" } {
    HTTP::header replace "Host" "/^([\s\S]*?)(domainname).*/g"
    HTTP::path "/"
    node 192.168.70.57 443
  }
}
  • I do not see an edit button but the irule would look like.

    when HTTP_REQUEST {
      if { [string tolower [HTTP::uri] ] contains "/?node=1" } {
        HTTP::header replace "Host" "/^([\s\S]*?)(domainname.com).*(node=1)/g"
        HTTP::path "/"
        node 192.168.70.57 443
      }
    }
    
  • Anthony,

     

    you created 2 threads about the same need.

     

    in the previous thread, you wanted to balance based on a different hostname, which is the recommended solution. but at the end, you changed to load balancing based on a query string....

     

    the issue is with this solution, only the first request will be sent to the good pool. next requests won't have this query string.

     

    I recommend you to explain the expected application behavior and not ask for an irule.

     

    After, we can help you to choose the best solution.