Forum Discussion
fcicala_29180
Nimbostratus
Jan 14, 2010http to https redirect with exceptions
Hello I am very new to iRules and just inherited a farm of 9.x F5.
I see that my predecessor is performing this task using the following iRule:
when HTTP_RESPONSE {
if { [HTTP::header Content-Type] starts_with "text/" }{
STREAM::expression "@http:@https:@"
STREAM::enable
} else {
STREAM::disable
}
}
I read about it and if I get it right this rules replaces everything that has the word HTTP with HTTPS?
The actual requirement I was given a few days ago is to replace links that contain HTTP with HTTPS if the link contains a specific word in it.
Can this be somehow achieved?
6 Replies
- The_Bhattman
Nimbostratus
The same type of Irule can be applied. It all depends on what what you are looking to replace. IS the specific word part of a link?
Bhattman - fcicala_29180
Nimbostratus
Yes it is part of a link.
How do you implement it then?
Lets assume I want to rewrite everything that contains/not contains a certain string? - The_Bhattman
Nimbostratus
Then you should be able to do the followingwhen HTTP_RESPONSE { if { [HTTP::header Content-Type] starts_with "text/" }{ STREAM::expression "@http:\\somedomain.com\word@https:\\someotherdomain.com\word@" STREAM::enable } else { STREAM::disable } }
Bhattman - hoolio
Cirrostratus
Hi,
That iRule is using a stream profile to replace instances of http: with https: in text-type response content. If you need to make it more specific, you can possibly use a regex or the STREAM_MATCHED and STREAM::match command.
If you'd like more detailed suggestions can you post a few examples of links you do and don't want rewritten?
Here are a few wiki pages with examples:
You might be able to tweak the find string of http: using a regex
http://devcentral.f5.com/Wiki/default.aspx/iRules/STREAM__expression.html
Or you could use the existing stream expression, but then add logic to the STREAM_MATCHED event to only rewrite the specific matches you want to using STREAM::replace.
http://devcentral.f5.com/Wiki/default.aspx/iRules/STREAM_MATCHED
http://devcentral.f5.com/Wiki/default.aspx/iRules/STREAM__replace
Aaron - The_Bhattman
Nimbostratus
It would be nice to get to update the post from within an email.
CB - fcicala_29180
Nimbostratus
Thanks. I will test this.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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