Forum Discussion
Darrell_Walker_
Nimbostratus
Jan 04, 2006Redirect based on port number
I'm looking for an irule that can do redirects based on certain port numbers.
For example:
http://server.domain.com:8888
to be redirected to:
https://server2.d...
Jan 04, 2006
I see several problems with your code
1) IP::client_port is not a valid command. Try using TCP::local_port instead.
2) Your first redirect has the port after the URI, it should be after the host and before the URI.
3) Your code has many situations for infinite loops.
It's not clear from your first request whether you want to redirect to different domains (as you stated in your description) or the same domain (as you did in your iRule).
If I go with the assumption that you want to do what you stated in words, something like this should work
when HTTP::REQUEST {
log local0. "routing host [HTTP::host] and port [TCP::server_port]"
if { ([TCP::local_port] == 8888) && ([HTTP::host] != "server2.domain.com") } {
log local0. "Redirecting to https://server2.domain.com:8888[HTTP::uri]"
HTTP::redirect https://server2.domain.com:8888[HTTP::uri]
} elseif { ([TCP::local_port] != 443) || ([HTTP::host] != "server3.domain.com") } {
log local0. "Redirecting to https://server3.domain.com[HTTP::uri]"
HTTP::redirect https://server3.domain.com[HTTP::uri]
}
}
I haven't fully thought out all combinations of your logic, but this should at least get you on the road to working things out.
Use the log statements to trace tests of your request flow (look in the /var/log/ltm file on the BIG-IP) and make sure all your options are covered.
Good luck and let us know what you end up with.
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects