Forum Discussion
Redirect 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 while caring on the rest of the URI.
Example: http://this.example.com/documents/dcm/viewer.asp Goes to
http://this.example.com/logs/error/errormanager.asp Goes to
http://this.example.com/reports/report/viewer.asp Goes to
I have this so far but it is not working. There may be an easier way than irule that I am not familiar with.
when HTTP_REQUEST { if { [HTTP::host] equals "this.example.com" } { if { [string tolower [HTTP::path]] starts_with "/documents/" } { HTTP::redirect "serverA:8080" [string trimleft [HTTP::uri] /documents] } elseif { [string tolower [HTTP::path]] starts_with "/logs/" } { HTTP::redirect "serverB" [string trimleft [HTTP::uri] /logs] } elseif { [string tolower [HTTP::uri]] starts_with "/reports/" } { HTTP::redirect "serverC" [string trimleft [HTTP::uri] /reports] } else { pool http://this.example.com [HTTP::uri] } } }
1 Reply
- StephanManthey
Nacreous
Hi Steve,
the
function will help:findstrwhen 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
command (jump table). Please note, that there is no action defined, if the initial condition (host name) does not match. Thanks, Stephanswitch
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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