Forum Discussion
Modify HTML content with an iRule
Hi,
I'd like to modify HTML content of a web page with an iRule.
In this case, I have a tag : <'h1>Text1 that I'd like to replace with <'h1>Text2 or with an image.
Can you help me?
Thanks a lot.
1 Reply
- Michael_Jenkins
Cirrostratus
A couple of things you can do.
If it's only a single static value you're trying to replace, I believe you can do in in a stream profile.
Otherwise, you can add an empty stream profile to you VIP and then perform the replacement(s) in an iRule using STREAM::expression. You should look at STREAM too to get familiar with how it'll work.
Always make sure you remove the Accept-Encoding header too so the response won't be compressed (if it is compressed, the rewrite won't work properly).
Here's a good example from the STREAM::expression wiki page:
Example which replaces http:// with https:// in response content Prevents server compression in responses when HTTP_REQUEST { Disable the stream filter for all requests STREAM::disable LTM does not uncompress response content, so if the server has compression enabled and it cannot be disabled on the server, we can prevent the server from sending a compressed response by removing the compression offerings from the client HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE { Check if response type is text if {[HTTP::header value Content-Type] contains "text"}{ Replace http:// with https:// STREAM::expression {@http://@https://@} Enable the stream filter for this response only STREAM::enable } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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