Forum Discussion
redirect to URI based upon client public
How to redirect traffic to certain uri based upon client public IP
- Lee_Sutcliffe
Nacreous
You can use an Local Traffic Policy or a simple iRule to achieve this:
when HTTP_REQUEST { if {[IP::addr [IP::client_addr] equals "1.2.3.4"]} { HTTP::redirect https://some.host.com/new-uri } }
However Be careful - Do you really need a redirect or do you just want to change the URI? If you redirect (HTTP 302) you can get stuck in a loop if the redirect comes to the same VIP.
If you just need to change the URI, you can try the following
when HTTP_REQUEST { if {[IP::addr [IP::client_addr] equals "1.2.3.4"]} { HTTP::uri /new-uri/ } }
- Lee_Sutcliffe
Nacreous
Hi Mohammed,
I've put together a more comprehensive iRule now I have more information about your requirements which should give you a good starting point. It uses a data-group using IP addresses and URIs as key/pair values.
The iRule will lookup the client IP against the datagroup elements, if there is a match it will return the data portion of the element (the URI) and set the outgoing URI to this value.
Please note this iRule hasn't been tested.
Datagroup
ltm data-group internal user_mapping_dg { records { 10.10.10.1 { data /uri1 } 10.10.10.2 { data /uri3 } 10.10.10.3 { data /uri3 } } type string }
iRule
when HTTP_REQUEST { set mapping_dg "user_mapping_dg" return data-group element (IP address) if client IP is listed. returns NULL/"" if not set ipMapping [class match -name [IP::addr [IP::client_addr]] equals $mapping_dg] if {$ipMapping ne ""} { set custom URI based on client IP - set in coresponding data portion of data-group set customUri [class match -value $ipMapping equals $mapping_dg] HTTP::uri $customUri } }
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