Forum Discussion

Ted_Kircos_1126's avatar
Ted_Kircos_1126
Icon for Nimbostratus rankNimbostratus
Nov 24, 2006

Need help - Before i pull my hair out!!!

Getting the following trying to add the irule below... Im stumped... Anyone see whats wrong or how to fix it?

 

 

line 8: [undefined procedure: http://] ["http://" + [HTTP::header "AP_LOCHOST"]]

 

line 9: [wrong args] [set replace "https://" + [HTTP::header "AP_LOCHOST"];]

 

 

when HTTP_RESPONSE {

 

if { [HTTP::status] starts_with "3" } {

 

set location [HTTP::header "Location"];

 

if { $location != "" } {

 

 

if {[HTTP::header "AP_NO_SSL_REDIR"] == "" } {

 

 

set find ["http://" + [HTTP::header "AP_LOCHOST"]];

 

set replace "https://" + [HTTP::header "AP_LOCHOST"];

 

regsub $find $location $replace newlocation ;

 

HTTP::header replace $location" newlocation;

 

}

 

}

 

return;

 

 

}

 

}
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Sorry... the format for string map is:

    set my_new_string [string map {$find1 $replace1 $find2 $replace2} $original_string]

    You can specify just one pair of find/replace strings if you want.

    If you wanted to minimize the steps, you could use something like this:

    
    when HTTP_RESPONSE {
       if { [HTTP::status] starts_with "3" and [HTTP::header "Location"] != "" and [HTTP::header "AP_NO_SSL_REDIR"] == ""} {
          HTTP::header "Location" [string map { [concat "http://"[HTTP::header "AP_LOCHOST"]] [concat "https://"[HTTP::header "AP_LOCHOST"] } HTTP::header "Location" ]
       }
    }

    Note that I didn't actually test this, but I think it matches the gist of what you're trying to do.

    If you run into problems, try updating the longer version and check the logging in /var/log/ltm to see where it's failing.

    Aaron
  • i am getting the following in the logs

     

     

    Nov 28 13:44:23 tmm tmm[710]: Rule dev1.clarica.com_https-irule : Status: 302

     

    Nov 28 13:44:23 tmm tmm[710]: Rule dev1.clarica.com_https-irule : location: https://dev1.clarica.com/bcheck.html?redir=/e/signin/index.asp

     

    Nov 28 13:44:23 tmm tmm[710]: Rule dev1.clarica.com_https-irule : find: http://

     

    Nov 28 13:44:23 tmm tmm[710]: Rule dev1.clarica.com_https-irule : replace: https://

     

    Nov 28 13:44:23 tmm tmm[710]: 01220001:3: TCL error: Rule dev1.clarica.com_https-irule - can't read "original_string": no such variable while executing "string map {$find1 $replace1 $find2 $replace2} $original_string"

     

     

    with the follow irule

     

     

    when HTTP_RESPONSE {

     

     

    if { [HTTP::status] starts_with "3" } {

     

     

    log local0. "Status: [HTTP::status]"

     

     

    set location [HTTP::header "Location"]

     

     

    log local0. "location: $location"

     

     

    if { $location != "" } {

     

     

    if {[HTTP::header "AP_NO_SSL_REDIR"] == "" } {

     

     

    set find [concat "http://" [HTTP::header "AP_LOCHOST"]]

     

     

    log local0. "find: $find"

     

     

    set replace [concat "https://" [HTTP::header "AP_LOCHOST"]]

     

     

    log local0. "replace: $replace"

     

     

    set my_new_string [string map {$find1 $replace1 $find2 $replace2} $original_string]

     

     

    log local0. "newlocation: $newlocation"

     

     

    HTTP::header replace $location $newlocation

     

     

    log local0. "replaced location header"

     

     

    }

     

     

    }

     

     

    }

     

     

    }
  • I believe hoolio meant for the following to be a format example, not an actual line in your code.

     

     

    set my_new_string [string map {$find1 $replace1 $find2 $replace2} $original_string]

     

     

    In other words, just change the "set newlocation" line as it was originally typed (or, rather, in your current rule replace the line above with the line below) to:

     

     

    set newlocation [string map {$find $replace} $location]
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Did you ever get this to work...?

     

     

    Using that approach, I'm finding that the variables within the map {} are not expanding.

     

     

    thanks!

     

    /deb
  • I have tried a number of options but I cannot get variables to work in the mapping section....

     

     

    Has anyone solved this.... or knows how to make it work.
  • Here is my working copY!

     

     

    when HTTP_RESPONSE {

     

     

    if { [HTTP::status] starts_with "3" } {

     

     

    set location [HTTP::header "Location"]

     

     

    if {$location != "" } {

     

     

    if {[HTTP::header "AP_NO_SSL_REDIR"] == "" } {

     

     

    set find "http://"

     

    append find [HTTP::header "AP_LOCHOST"]

     

     

    set replace "https://"

     

    append replace [HTTP::header "AP_LOCHOST"]

     

     

    set newlocation [string map [list $find $replace] $location]

     

     

    HTTP::header replace "Location" $newlocation

     

     

    }

     

     

    }

     

     

    }

     

     

    }
  • Thanks for the last piece of the puzzle.... it was the "list" function that solved my problem.

     

     

     

    if {[HTTP::is_redirect]}{

     

     

    set find ":25620/"

     

     

    set replace "/"

     

     

    set location [HTTP::header value Location]

     

     

    HTTP::header replace Location [string map [ list $find $replace] $location]

     

     

    log [string map [ list $find $replace] $location]

     

     

    log [string map { ":25620/" "/"} $location]

     

     

    }

     

    }

     

     

    Jan 30 10:23:51 tmm tmm[1385]: 01220002:6: Rule lng-ln-cert-certlexisgw.lexis.com-http : http://certlexisgw.lexis.com/hbeat/

     

    Jan 30 10:23:51 tmm tmm[1385]: 01220002:6: Rule lng-ln-cert-certlexisgw.lexis.com-http : http://certlexisgw.lexis.com/hbeat/