Forum Discussion
G__246_ran___19
Altostratus
Mar 08, 2017Redirect when both Host and Path are equal
Hello, I have a virtual server who has many different host names and path, one of those i need to have a redirect like this:
If hostname is and path is / redirect to
How shod I write the iRu...
Kai_Wilke
MVP
Mar 08, 2017Hi Göran,
you may try either a nested
[switch] or [if] condition to parse the HOST and then the Path (general purpose) or use a combined [if] condition (tailordered purpose).
Example 1: Using general purpose nested
commands.[switch]
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::host]] {
"www.domain.de" {
Requests for www.domain.com
switch -glob -- [string tolower [HTTP::path]] {
"/" {
Requests for URI = /
HTTP::redirect "/abc/"
}
default {
Requests for URI = *
}
}
}
"www.domain.com" {
Requests for www.domain.com
}
"www.domain.net" {
Requests for www.domain.net
}
default {
Unknown HOST-name
}
}
}
Example 2: Using general purpose nested
commands.[if]
when HTTP_REQUEST {
set low_host [string tolower [HTTP::host]]
if { $low_host eq "www.domain.de" } then {
Requests for www.domain.de
set low_path [string tolower [HTTP::path]]
if { $low_path equals "/" } then {
Requests for URI = /
HTTP::redirect "/abc/"
} else {
Requests for URI = *
}
} elseif { $low_host equals "www.domain.com" } then {
Requests for www.domain.com
}
} elseif { $low_host equals "www.domain.net" } then {
Requests for www.domain.net
} else {
Unknown HOST-name
}
}
Example 3: Using a tailordered
command (to support just your requirements)[if]
when HTTP_REQUEST {
if { ( [string tolower [HTTP::host]] equals "www.domain.de" )
and ( [HTTP::path] equals "/" } then {
Requests for www.domain.de/
HTTP::redirect "/abc/"
} else {
Request for another HOST-name or another Path
}
}
Note: The general purpose examples can be easily extended to support various other things. The benefit of such a syntax is that you get scalable and unified method to control your traffic as needed.
Cheers, Kai
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