Forum Discussion
irule for rewrite
Hi Everyone,
So we have a setup where the user access the VS of F5 "https://my.url.com".
Our current setup is using client source IP based for load balancing (odd-even):
when HTTP_REQUEST {
set lastoctet [lindex [split [IP::client_addr] .] 3]
if { [expr $lastoctet % 2] == 1 } {
HTTP::respond 301 Location "https://our.url1.com"
} else {
HTTP::respond 301 Location "https://our.url2.com"
}
}
My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also?
i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to and he will see that url ( on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to and he will see that url ( on his browser
WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to and but he will see on his url is https://my.url.com on his browser
Is this possible?
11 Replies
- Vernon_97235Historic F5 Account
Yes. Rewrite the HTTP Host header as it is proxied from client-side request to server-side request:
when HTTP_REQUEST { if { [getfield [IP::client_addr] . 4] & 0x01 == 1 } { HTTP::host "our.url1.com" } else { HTTP::host "our.url2.com" } }- Allanwynn_16283
Nimbostratus
hi? can you help me with my question? My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also? i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and he will see that url (https://our.url2.com) on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and he will see that url (https://our.url1.com) on his browser WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser - Vernon_97235Historic F5 AccountI apologize if I missed something you wanted (e.g., @stanislas's pool selection) but I do believe that this accomplishes what you request. I altered the mechanism for octet extraction and odd/even selection in order to make it more compact and slightly faster. More to the point, server virtual host selection is generally a function of the submitted HTTP Host header value. Changing that in HTTP_REQUEST will change it between the BIG-IP and the Pool Member only. Thus, the client will not "know" that a change was made at all (and as such, the originally selected URL will remain unaltered in the user-agent/browser).
- Allanwynn_16283
Nimbostratus
Hi, thank you for your feedback. But what if we have an issue with the communication between F5 big ip and the servers, wherein creating basic load balancing setup: VS 443 and pool is port 80, so we decided just to redirect it with the server itself. Can we use this for this setup for added security? WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
- VernonWells
Employee
Yes. Rewrite the HTTP Host header as it is proxied from client-side request to server-side request:
when HTTP_REQUEST { if { [getfield [IP::client_addr] . 4] & 0x01 == 1 } { HTTP::host "our.url1.com" } else { HTTP::host "our.url2.com" } }- Allanwynn_16283
Nimbostratus
hi? can you help me with my question? My question is, is there an irule that i can use with this irule(odd-even source ip based) that will rewrite the location url into https://my.url.com also? i.e. NOW: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and he will see that url (https://our.url2.com) on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and he will see that url (https://our.url1.com) on his browser WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser - VernonWells
Employee
I apologize if I missed something you wanted (e.g., @stanislas's pool selection) but I do believe that this accomplishes what you request. I altered the mechanism for octet extraction and odd/even selection in order to make it more compact and slightly faster. More to the point, server virtual host selection is generally a function of the submitted HTTP Host header value. Changing that in HTTP_REQUEST will change it between the BIG-IP and the Pool Member only. Thus, the client will not "know" that a change was made at all (and as such, the originally selected URL will remain unaltered in the user-agent/browser). - Allanwynn_16283
Nimbostratus
Hi, thank you for your feedback. But what if we have an issue with the communication between F5 big ip and the servers, wherein creating basic load balancing setup: VS 443 and pool is port 80, so we decided just to redirect it with the server itself. Can we use this for this setup for added security? WHAT WE WANT: if user's IP is 10.10.10.20 and access https://my.url.com he will be redirected to https://our.url2.com, and but he will see on his url is https://my.url.com on his browser and if user's IP is 10.10.10.21 and access https://my.url.com he will be redirected to https://our.url1.com, and but he will see on his url is https://my.url.com on his browser
- Stanislas_Piro2
Cumulonimbus
Hi Allanwynn,
to display the user must request https://my.url.com.
So, the solution is to not redirect users to https://my.url1.com or https://my.url2.com but assign pool member different and rewrite host header.
when HTTP_REQUEST { set lastoctet [lindex [split [IP::client_addr] .] 3] if { [expr $lastoctet % 2] == 1 } { pool pool1 HTTP::host "our.url1.com" } else { pool pool2 HTTP::host "our.url2.com" } } - Stanislas_Piro2
Cumulonimbus
the irule provided does not redirect user to url1 or url2 but forward the request to the right pool with host header rewriting (maybe useless).
Why are you using odd-even load balancing instead of builtin load balancing method?
- Stanislas_Piro2
Cumulonimbus
If you have issues with direct load balancing, this may be a persistence issue.
did you try to resolve it before trying to change behavior to redirect with 2 urls?
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