Forum Discussion
Greg_Bishop_104
Jun 27, 2011Nimbostratus
redirect subdomain to append to uri
Hey guys, I've done a little bit with iRules but not very much. What I'm looking for is to redirect a large number of subdomains such as the following:
greg.domain.com --> www.domain.com/sit...
hooleylist
Jun 28, 2011Cirrostratus
Hi Greg,
You can use the string range, getfield or scan command to parse the subdomain from a host header value:
when HTTP_REQUEST {
Check for a non-null length host header
if {[string match {*[a-zA-Z]*} [HTTP::host]]}{
Use string commands to parse the subdomain
set subdomain [string range [HTTP::host] 0 [expr {[string first . [HTTP::host]] -1}]]
Use the getfield command to parse the subdomain
set subdomain [getfield [HTTP::host] . 1]
Use scan to parse the subdomain
scan [HTTP::host] {%[^.]} subdomain
}
}
I'd guess that getfield is probably the simplest and potentially the most efficient option to do this.
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