Forum Discussion
adamo_1516
Nimbostratus
Aug 14, 2007exception logic for selective https redirect
yes, i'm losing my mind.
i've got a rule we put in place to take specific subdomains and statically redirect the URL's to https. it works great, but we're now seeing we need to add exception...
hoolio
Cirrostratus
Aug 14, 2007First, I saw a more eloquent way to parse the subdomain from the getfield wiki page (Click here)"
[getfield [string tolower [HTTP::host]] "example.com" 1]
This would set the host header value to lower case and then split the value on the literal string "example.com" and return the 1st field (the subdomain).
You can use a class (called a datagroup in the GUI) which contains the subdomains you want to redirect. You can create a datagroup under Local Traffic >> iRules >> Datagroups.
You can then use matchclass (Click here) to check if the requested host starts with one of the subdomains in the class.
class redirect_hosts {
subdomain1.
subdomain2.
subdomain3.
}
when HTTP_REQUEST {
if {([matchclass [getfield [string tolower [HTTP::host]] "example.com" 1]] equals $::redirect_hosts) and (not ([HTTP::uri] contains "SpecialUrl"))} {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}The class approach is cleaner as far as the rule goes. But it might be slightly faster to use an if and then a switch statement:
if {not ([HTTP::path] contains "SpecialUrl")}{
use getfield to split the host header value and grab anything that comes before "example.com"
set that remaining string to lower case
switch [getfield [string tolower [HTTP::host]] "example.com" 1] {
subdomain1. -
subdomain2. -
subdomain3. {
redirect matching requests to https
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
default {
do nothing; let request be sent to pool per VIP configuration
}
}
}[edited to fix the order of string tolower and getfield]
Aaron
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
