Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology

Possible Rewrite Issues

For the longest time we only had the APM licensed and not the LTM module. This prevented me from using rewrite profiles in my designs and infrastructure. For rewrites I used the following iRule:

when RULE_INIT {
  # Log debug output to ltm logs - 1=yes, 0=no
set rwdebug 0
  # Set up variables for the irule and sets the default behavior of the STREAM profile. .
  set chk_resp_rw 0
  set rwdebug 0
  set clientHost "externalname.domain.com"
  set serverHost "servername.domain.com"  
  # Below check if the http request is from the HOST and starting URI that requires the rewrite.     
  if {[string tolower [HTTP::host]] equals $clientHost} {
                HTTP::header replace Host $serverHost 
                HTTP::uri /externalname/[HTTP::uri]
                set chk_resp_rw 1 
                if {$rwdebug}{ log local0. "Host Rewrite: [HTTP::host] , Context URI = [HTTP::uri]"} 

  # Check server response for rewrites
  if {$chk_resp_rw}{
                # STREAM expression changes all references in the response payload with the desired rewrite
    if {[HTTP::header value Content-Type] contains "text"}{  
      STREAM::expression @$serverHost@$clientHost@
     if {$rwdebug}{ log local0. "response Rewrite done: "} 
                # Check Location header for desired rewrite
    if { [HTTP::header exists Location]}{
       HTTP::header replace Location [string map -nocase {$serverHost $clientHost} [HTTP::header Location]]           

Everything seemed to work fine until we purchased the licensing for the LTM module. I am trying to do the following rewrite:

https://externalname.domain.com -> https://servername.domain.com/externalname

Just wondering if this my irule no longer works because we have the LTM module or should i be using the rewrite profile?

Rate this Question

Answers to this Question