12-Sep-2022 21:45 - edited 12-Sep-2022 22:32
I am looking for an iRule for this scenario:
A VIP handles traffic to multiple host fields on the same IP address. This is always mapped to the same server pool. Based on the requested host field in the HTTP GET, the F5 LTM needs to change the port from 8080 to either 81 or 80 or 8081.
For example:
if the requested host is test.com:8080 then it should be sent to test.com:80
If the requested host is abc.com:8080 then it should be sent to abc.com:81
Etc.
Could any of you kind souls provide an example for how to do this?
13-Sep-2022 06:23 - edited 13-Sep-2022 06:25
You can try something like this.. I haven't tested but hopefully work.
when HTTP_REQUEST {
if { ([getfield [HTTP::host] ":" 1]:[TCP::local_port]) equals "8080" } {
HTTP::respond 301 Location "http://[HTTP::host]/abc.html"
# http://[HTTP::host]:80/abc.html >>> Same like http://[HTTP::host]/abc.html
}
}
13-Sep-2022 20:59
Thank you so much Samir! BUT ... I am looking for something like this:
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] starts_with "abc.com:8080" } { TCP::local_port replace 80 } }
Does this look like it would work to take the connection on TCP/8080 from the client and send it to the server pool on TCP/80?
13-Sep-2022 21:11
I think this might be correct?
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "abc.com:8080" } { set new_port 80 } }
Please let me know what you think