Forum Discussion
Brian_Deitch_11
Apr 23, 2009Historic F5 Account
Replace HTML code with multiple links
So here is my dilemma. I need to create an iRule that will:
1. Match a link
2. Replace each link with one from a list.
So, on the response request, the F5 WA will match data.mysite.com and replace each data.mysite.com with data1.mysite.com thru data10.mysite.com. I'm sure this has already been done before but I'm clueless as to what to search for.
FYI...They reason why we just do not use multiconnect in the WA policy is the data hosted on data.mysite is hosted externally from the WA.
Thanks in advance,
Brian
- James_Quinby_46Historic F5 AccountI just want to make sure I understand...for all fully qualified URLs in a returned HTML page (IMG SRC and HREFs), you want to replace 'data.' with 'data{n}.', where n={1..10}?
- Brian_Deitch_11Historic F5 AccountThat's exactly what I'm trying to accomplish. Thank you.
- Brian_Deitch_11Historic F5 AccountOkay..I'm a little bit closer here....
when HTTP_RESPONSE { if { [HTTP::status] == 200} { find and replace STREAM::expression ",http://data.,http://data1.," STREAM::enable } }
- James_Quinby_46Historic F5 AccountYeah, I was going that way too but I think the stream profile substitution only does 1 replacement at a time. I started hacking away at something based on the SSN masking iRule here:
- Brian_Deitch_11Historic F5 AccountWell it took an act of God and some great help from Greg with F5 support but we accomplished the task at hand!
when RULE_INIT { set this to 0 for production set debug 1 } when HTTP_RESPONSE { Counter goes from 1 to 10 set data_counter 1 Disable the stream filter by default STREAM::disable Check if response type is html or javascript if { ( [HTTP::header value Content-Type] contains "text/html" ) or ( [HTTP::header value Content-Type] contains "javascript" )}{ Match any http://data. and don't automatically replace it with anything STREAM::expression "@http://data\.mydomain\.com@DUMMY@" Enable the stream filter for this response only STREAM::enable } } when STREAM_MATCHED { if { $::debug >= 1 } { log local0. "[IP::client_addr]:[TCP::local_port]: matched: [STREAM::match], replaced with: [string map [list "data" [format "data%u" $data_counter] ] [STREAM::match] ]" } STREAM::replace [string map [list "data" [format "data%u" $data_counter] ] [STREAM::match] ] Iterate the data_counter set data_counter [ expr { $data_counter % 10 + 1 } ] }
- hoolio
Cirrostratus
That's a great solution. Thanks for posting it.
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