cancel
Showing results for 
Search instead for 
Did you mean: 

policy to replace host value

Sam10
Altostratus
Altostratus

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 2

Andrew-F5
F5 Employee
F5 Employee

It looks like you may be able to accomplish your goal using a rewrite profile, would be more efficient then an iRule. See the article below and reply back with your thoughts.

 

https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/ltm-implementations-12-1-0/17.h...

Sam10
Altostratus
Altostratus

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]]

 

 }