Forum Discussion

Sam10's avatar
Sam10
Icon for Altostratus rankAltostratus
Sep 20, 2020

policy to replace host value

I am trying to create a policy to replace the host in the header.

 

i.e is when users access myaccount.xyz.com F5 need to replace it with myaccount.abc.com and send the response to the server . And when server sends the response F5 should again replace the host to xyz.com and send to client.

 

I am able to get it working using an irule with wildcard but when it comes to specific url my irule is not working with the response.

 

when HTTP_REQUEST {

  set external_hostname [HTTP::host]

  set sub_hostname [substr [HTTP::host] 0 ".xy.com"]

  set internal_hostname $sub_hostname.abc.com

 

  HTTP::header replace "Host" $internal_hostname

}

when HTTP_RESPONSE { 

      HTTP::header replace Location [string map -nocase "$internal_hostname $external_hostname" [HTTP::header Location]]

}

 

Which specific host below irule is not working when i add http response, it is replacing all the hosts to myaccount.abc.com login page.

 

when RULE_INIT {

   set ::external_hostname "myaccount.xyz.com" 

   set ::internal_hostname "myaccount.abc.com" 

 } 

 when HTTP_REQUEST {  

      HTTP::header replace "Host" $::internal_hostname

 } 

 when HTTP_RESPONSE {  

      HTTP::header replace Location [string map -nocase "$::internal_hostname $::external_hostname" [HTTP::header Location]]

 }

 

 

 

 

 

 

2 Replies

  • Andrew

     

    I finally got it working with the below irule but trying to add multiple urls in the request and not getting my syntax correct for the http response. Any help appreciate it.

    when HTTP_REQUEST {  

          set external_hostname "tools.xyz.com" 

          set internal_hostname "tools.abc.com"  

     

          set external_hostname1 "test.xyz.com" 

          set internal_hostname1 "test.abc.com"

         if { ([HTTP::host] equals $external_hostname) } {

          HTTP::header replace Host $internal_hostname

          }

     

          if { ([HTTP::host] equals $external_hostname1) } {

          HTTP::header replace Host $internal_hostname1

          }

     

     }

     

     when HTTP_RESPONSE { 

          set external_hostname "tools.xyz.com"

          set internal_hostname "tools.abc.com"  

     

          set external_hostname1 "test.xyz.com" 

          set internal_hostname1 "test.abc.com"

          log local0. "The location header [HTTP::header Location] on response"

          HTTP::header replace Location [string map -nocase "$internal_hostname $external_hostname" [HTTP::header Location]]

          HTTP::header replace Location [string map -nocase "$internal_hostname1 $external_hostname1" [HTTP::header Location]]

     

     }