Forum Discussion
Mhelvin_Mory_63
Nimbostratus
Aug 11, 2006i-Rule to change http header
Hi All
I'm using BIG-IP as SSL termination and loadbalancer for SAP web application. But some web contents are not display properly and suspect this could be cause by some contents not conve...
hoolio
Cirrostratus
Aug 11, 2006There a a few different ways to replace one string with another. You can use string map (Click here) with the format (where all variables are strings):
set $my_val [string map { $original $replacement } $content_to_search
Here is one method to replace http with https in a header called my_header:
when HTTP_REQUEST {
if { [HTTP::header exists my_header] }{
save current value for my_header
set my_val [HTTP::header value my_header]
log current value
log local0. "my_val: $my_val"
replace all instances of http with https in the string
set my_new_val [string map { http https } $my_val]
log updated value
log local0. "my_new_val: $my_new_val"
replace the value of my_header with the updated string
HTTP::header replace my_header $my_new_val
log updated header value
log local0. "replaced header value: [HTTP::header value my_header]"
}
}Result:
Aug 11 08:07:26 tmm tmm[1222]: Rule string_replace_rule : my_val: http://test.com
Aug 11 08:07:26 tmm tmm[1222]: Rule string_replace_rule : my_new_val: https://test.com
Aug 11 08:07:26 tmm tmm[1222]: Rule string_replace_rule : replaced header value: https://test.com
Or with fewer variables and no logging:
when HTTP_REQUEST {
if { [HTTP::header exists my_header] }{
HTTP::header replace my_header [string map { http https } [HTTP::header value my_header]]
}
}You could also use one of the other TCL string commands to do this replacement (Click here).
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
