Forum Discussion
Steve_Romanowsk
Nimbostratus
Mar 23, 2015Redirect based on part of path
I need to have a single vhost name (this.example.com) going to multiple applications depending on the first part of the path extension, then need to eliminate that first part of the path extension wh...
StephanManthey
Nacreous
Mar 23, 2015Hi Steve,
thefindstr function will help:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "this.example.com" } {
if { [string tolower [HTTP::path]] starts_with "/documents/" } {
HTTP::redirect "http://serverA:8080[findstr [string tolower [HTTP::uri]] "/documents" [string length "/documents"]]"
} elseif { [string tolower [HTTP::path]] starts_with "/logs/" } {
HTTP::redirect "http://serverB[findstr [string tolower [HTTP::uri]] "/logs" [string length "/logs"]]"
} elseif { [string tolower [HTTP::uri]] starts_with "/reports/" } {
HTTP::redirect "http://serverB[findstr [string tolower [HTTP::uri]] "/reports" [string length "/reports"]]"
} else {
HTTP::redirect "http://this.example.com[HTTP::uri]"
}
}
}
There are smarter solutions based on the
switch command (jump table).
Please note, that there is no action defined, if the initial condition (host name) does not match.
Thanks, StephanHelp 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