Forum Discussion
John_Nootens_45
Nimbostratus
Jun 14, 2005How do I redirect client dest port
1) Here is the rule I am trying. Does this look correct. I want to re-direct the client to talk on a unique port.
when HTTP_REQUEST {
if { [HTTP::host] contains "marstest."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5878
}
}
Here is what I want to do:
If the URL (ie: "marstest.xxx.com") contains "marstest."
then HTTP redirect to http://marstest.xxx.com:5878
2) Then I will probably need to do this for 10-20 URLs. Does this syntax look correct?
when HTTP_REQUEST {
if { [HTTP::host] contains "marstest."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5878
}
if { [HTTP::host] contains "other."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5902
}
}
Or will I need to nest if/else's 10-20 times, like this? And if this is the right way, how far can I nest the if/else's?
when HTTP_REQUEST {
if { [HTTP::host] contains "marstest."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5878
}
else if { [HTTP::host] contains "other."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5902
}
else if { [HTTP::host] contains "otherxxx."} {
HTTP::redirect HTTP://[HTTP::host][HTTP::uri]:5977
}
}
- This looks good with one issue: The format for a url is the following
when HTTP_REQUEST { if { [HTTP::host] contains "marstest."} { HTTP::redirect HTTP://[HTTP::host]:5878[HTTP::uri] } elseif { [HTTP::host] contains "other."} { HTTP::redirect HTTP://[HTTP::host]:5902[HTTP::uri] } elseif { [HTTP::host] contains "otherxxx."} { HTTP::redirect HTTP://[HTTP::host]:5977[HTTP::uri] } }
class domain_redirects { "www.marstest.com :5878" "www.other.com :5902" "www.otherxxx.com :5977" }
when HTTP_REQUEST { log local0. "domain_redirect iRule" Look for an entry in the domain_redirects data group that starts with the value of the HTTP::host value set match [findclass [HTTP::host] $::domain_redirects] log local0. "Match: $match" if { "" ne $match } { log local0. "Found Match! Extract the port portion of the data group item Check out http://tmml.sourceforge.net/doc/tcl/string.html for documentation on the TCL string command. set thePort [string range $match [string last ":" $match] 999] log local0. "thePort: $thePort" set theRedirect http://[HTTP::host]$thePort[HTTP::uri] log local0. "theRedirect: $theRedirect" Redirect to the specified port on the given server HTTP::redirect $theRedirect } else { log local0. "Host [HTTP::host] not in domain_redirects data group" } }
class domain_redirects { "www.marstest.com:5878" "www.other.com:5902" "www.otherxxx.com:5977" }
when HTTP_REQUEST { log local0. "domain_redirect iRule" Look for an entry in the domain_redirects data group that starts with the value of the HTTP::host value set newHost [findclass [HTTP::host] $::domain_redirects] log local0. "newHost: $newHost" if { "" ne $newHost } { log local0. "Found Host! Redirect to the updated host with a new port HTTP::redirect http://$newHost[HTTP::uri] } else { log local0. "Host [HTTP::host] not in domain_redirects data group" } }
when HTTP_REQUEST { set newHost [findclass [HTTP::host] $::domain_redirects] if { "" ne $newHost } { HTTP::redirect http://$newHost[HTTP::uri] } }
- kiamars_51328
Nimbostratus
Hi how do I elemented the port, basically I don't to see the port that gets reditect in my browser. - hoolio
Cirrostratus
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