Forum Discussion
can anyone provide f5 script
If you want to perform a redirect (that is, respond to user-agent with a 302 and a Location header):
when HTTP_REQUEST {
if { [getfield [HTTP::host] : 1] eq "x1y1z1.xyzglobal.local" } {
HTTP::redirect "http://x2y2z2.x2y2z2global.local:8080[HTTP::uri]"
}
}
If you care to redirect only when the uri-path is "/":
when HTTP_REQUEST {
if { [HTTP::path] eq "/" and [getfield [HTTP::host] : 1] eq "x1y1z1.xyzglobal.local" } {
HTTP::redirect "http://x2y2z2.x2y2z2global.local:8080[HTTP::uri]"
}
}
This assumes that this iRule is attached to a Virtual Server listening on port 8080.
If you want to transparently transform the Request-URI (that is, change it before sending it to the pool member, but retain original URL for user-agent):
when HTTP_REQUEST {
if { [getfield [HTTP::host] : 1] eq "x1y1z1.xyzglobal.local" } {
HTTP::host "x2y2z2.x2y2z2global.local"
}
}
Having said all of that, it actually looks like you want to perform a redirect such that if the request is for then the target is . If this is the case, then the trick is, of course, the extraction. Assuming that the pattern is strictly x1y1z1.xyzglobal.local (and x, y and z are exactly one digit each), then:
when HTTP_REQUEST {
if { [scan [getfield [HTTP::host] : 1] "%1d1%1d1%1d1.%3dglobal.local" a1 a2 a3 b] == 4 } {
if { "$a1$a2$a3" eq $b } {
HTTP::redirect "http://${a1}2${a2}2${a3}2.${a1}2${a2}2${a3}2global.local:8080[HTTP::uri]"
}
}
}
Again, if you want transparent rewriting, then you must use
HTTP::host with the rewritten Host header.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