Forum Discussion

JohnL_247646's avatar
JohnL_247646
Icon for Nimbostratus rankNimbostratus
Feb 03, 2016

Need help with Cisco ACE header rewrite to irule

I need some help doing this conversion from Cisco Ace to iRule. There is a header request that convert the users URL request from "hostA.companyA.com/whatever/comes/after" replace "host1.companyA.com:64592/whatever/comes/after" and a header response that converts it back so the user will only see hostA.companyA.com/whatever/comes/after. We need to make the rewrite transparent to the user and the '/whatever/comes/after' will need to stay the same.

 

There is the ACE code..

 

action-list type modify http login header rewrite request Host header-value "hosta[.]companyA[.]com(.)" replace "host1.companyA.com:64592%1" header rewrite response Location header-value "https://host1.companyA.com:64592/(.)" replace "https://hosta.companyA.com/%1"

 

Thanks

 

4 Replies

  • Hi John,

    an ACE action-list of...

    action-list type modify 
        http login 
                header rewrite request Host header-value "hosta[.]companyA[.]com(.)" replace "host1.companyA.com:64592%1" 
                header rewrite response Location header-value "https://host1.companyA.com:64592/(.)" replace "https://hosta.companyA.com/%1"
    

    ... could be translated to ...

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "hosta.companya.com" } then {
            HTTP::header replace Host "host1.companyA.com:64592"
        }
    }
    when HTTP_RESPONSE {
        if { [string tolower [HTTP::header value Location]] starts_with "https://host1.companya.com:64592" } then {
            HTTP::header replace Location "https://hosta.companyA.com[getfield [HTTP::header value Location] ":64592" 2]"
        }
    }
    

    Note: I'm using

    [string tolower]
    to make it more robust. So keep an eyee on lower CASE formating for the equals and starts_with comparsions.

    Cheers, Kai

    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      Getfield splits the given input on every ":64592" and then uses the 2nd block...
  • I modified that a bit in my testing enviroment when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "lb.abc.com" } then { HTTP::header replace Host "10.10.192.111" } } when HTTP_RESPONSE { if { [string tolower [HTTP::header value Location]] starts_with "http://" } then { HTTP::header replace Location "https://lb.abc.com[getfield [HTTP::header value Location] ":80" 2]" } } Not working and keep getting this in the ltm log. error: [undefined procedure: HTTP::Location][HTTP::Location]