Forum Discussion
Miron_du_Plessi
Nimbostratus
Nov 03, 2007HTTP Redirect based on URI
Hi,
I have a webserver behind our LTM. Access to the webserver is working correctly when users use the full url of
https://remedy.xxx.net/arsys/home
however we are trying...
hoolio
Cirrostratus
Nov 05, 2007Hi Miron,
You can add log statements to your rule and then tail the /var/log/ltm log file (tail -f /var/log/ltm) to see what values you're getting:
when HTTP_REQUEST {
log local0. "URI: [HTTP::uri]"
if { $uri ends_with "/remedy" } {
log local0. "URI: [HTTP::uri] matched /remedy check"
HTTP::redirect "https://remedy.xxx.net/arsys/home"
} elseif { $uri ends_with "/remedy.xxx.net" } {
log local0. "URI: [HTTP::uri] matched /remedy.xxx.net check"
HTTP::redirect "https://remedy.xxx.net/arsys/home"
}
}I think you're mixing up the Host header value and the URI that HTTP::uri returns. If a client requests https://test.example.com/path/to/file.ext, [HTTP::host] will return "test.example.com". [HTTP::uri] will return "/path/to/file.ext".
You probably want to try something like this:
when HTTP_REQUEST {
log local0. "Host: [HTTP::host], URI: [HTTP::uri]"
if { [string tolower [HTTP::host]] eq "remedy"} {
log local0. "Host: [HTTP::host] matched remedy check"
HTTP::redirect "https://remedy.xxx.net/arsys/home"
} elseif { [string tolower [HTTP::host]] eq "remedy.xxx.net" } {
log local0. "Host: [HTTP::host] matched remedy.xxx.net check"
HTTP::redirect "https://remedy.xxx.net/arsys/home"
}
}Alternately, if you want to redirect any request to the VIP that's not made to remedy.xxx.net, you could just do a single test:
when HTTP_REQUEST {
log local0. "Host: [HTTP::host], URI: [HTTP::uri]"
if { not ([string tolower [HTTP::host]] eq "remedy.xxx.net")} {
log local0. "Host: [HTTP::host] didn't match remedy.xxx.net; redirecting."
HTTP::redirect "https://remedy.xxx.net/arsys/home"
}
}Aaron
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
