Forum Discussion
David_L_
Nimbostratus
Oct 05, 2007HTTP Redirect based on protocol
It seems like this should be simple...
I want to use a single rule on multiple virtual servers to redirect traffic to another site. Simplified -
If the incoming request is HTTP://host.com/?...
Deb_Allen_18
Oct 05, 2007Historic F5 Account
The simplest way would be to test the port on which the request is received, and set the protocol string based on that.
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] contains ".com"}{
set host [string map -nocase {.com .net} [HTTP::host]]
if {[TCP::local_port] == 443 {
set proto "https"
} else {
set proto "http"
}
HTTP::redirect "$proto://$host[HTTP::uri]"
}
}
(Since you mentioned you want this to work on multiple VS, I took the liberty of also adding a string map function to re-write any .com hostname to .net, which you can of course adjust to match your specific requirements.)HTH
/deb
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