Forum Discussion

Rosieodonell_16's avatar
Nov 03, 2016

Need help with rewrite but can't use profiles :(

Love the community here and i am looking for a little help. To start off i only have APM enabled so i can't use the LTM rewrite profiles. (really sucks). I need to create the following re-write:

https://field.test2.company2.com/bix-test/interface.aspx -> https://test.company.com/LegacyRequest/Interface.aspx

I have been toying with the following irule but i think i need a little help because i get page can't be displayed.

when RULE_INIT {
   Log debug output to ltm logs - 1=yes, 0=no
set rwdebug 0
}
when HTTP_REQUEST {
   Set up variables for the irule and sets the default behavior of the STREAM profile. .
  set chk_resp_rw 0
  set clientHost "field.test2.company2.com"
  set serverHost "test.company.com"  
  STREAM::disable
   Below check if the http request is from the HOST and starting URI that requires the rewrite.     
  if {[string tolower [HTTP::host]] equals $clientHost && [string tolower [HTTP::uri]] starts_with "/bix-test/"}{
                HTTP::header replace Host $serverHost 
                HTTP::uri /LegacyRequest/Interface.aspx
                set chk_resp_rw 1 
                if {$wdebug}{ log local0. "Host Rewrite: [HTTP::host] , Context URI = [HTTP::uri]"} 
   }
  }
when HTTP_RESPONSE {
   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@
      STREAM::enable
     if {$wdebug}{ 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]]           
    } 
  } 
}

I have stream turned on, on the virtual server. Any advice would be great guys, thanks!

3 Replies

  • Hi,

    With a fast review, I see this possible mistake (variable name declaration):

    set rwdebug 0

    But you are calling for

    if { $wdebug }{ log local0. ".....

    So, it should be:

    if { $rwdebug }{ log local0. ".....

    And maybe the:

    HTTP::header replace Host $serverHost

    should be just this:
    HTTP::host $serverHost

    I have not tested, so, I hope it helps.

  • Here is some of the errors from the ltm file

    Nov  3 07:16:34 DCAK12F5A err mcpd[8848]: 01070151:3: Rule [/Common/benson_rewrite_irule] error: /Common/benson_rewrite_irule:14: error: [undefined procedure: /LegacyRequest/Interface.aspx&8221][/LegacyRequest/Interface.aspx&8221;]
    Nov  3 07:17:44 DCAK12F5A err mcpd[8848]: 01070151:3: Rule [/Common/benson_rewrite_irule] error: /Common/benson_rewrite_irule:14: error: [unexpected extra argument "Uri"][HTTP::uri replace Uri &8220;] /Common/benson_rewrite_irule:14: error: [undefined procedure: /LegacyRequest/&8221][/LegacyRequest/&8221;]