Forum Discussion
Redirecting Traffic Using iRules
Here is the goal.
Traffic from 192.168.1.0 to LTM --> http://example.com/(rest of the url)
Traffic from anywhere else to LTM --> pool_A
Here is my attempt so far.
when HTTP_REQUEST {
if { [[IP::remote_addr] starts_with "192.168.1."] }
{ HTTP::redirect "http://example.com/[HTTP::uri] }
else {pool my_pool}
}
I don't know much about iRules as I am just now learning them, but would love to know what needs to happen. Basically I want to F5 to redirect traffic away from the F5 to another server if it comes from 192.168.1.0/24. If it doesn't come from that address then go to the specified pool.
4 Replies
- What_Lies_Bene1
Cirrostratus
This should do it;when HTTP_REQUEST { if { [IP::addr [IP::client_addr] starts_with 192.168.1.] } { HTTP::redirect "http://example.com/[HTTP::uri]" } else { pool my_pool } } - Mohamed_Lrhazi
Altocumulus
I think you should use the correct ip address tests, not a string comparison, like:
[IP::addr [IP::client_addr] equals 10.0.0.0/8]
See: https://devcentral.f5.com/wiki/iRules.IP__addr.ashx - What_Lies_Bene1
Cirrostratus
Thanks Mohamed, so it would look like this;when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 192.168.1.0/24] } { HTTP::redirect "http://example.com/[HTTP::uri]" } else { pool my_pool } } - nitass
Employee
i just removed / after example.com because it is included in HTTP::uri.when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 192.168.1.0/24] } { HTTP::redirect "http://example.com[HTTP::uri]" } else { pool my_pool } }
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