Forum Discussion
Simon_Wright_85
Feb 27, 2007Nimbostratus
Subdomain iRule question
Hi all
I am just starting out creating iRules for our Big-ip boxes and i have no idea where to start with this one.
What i am trying to do is to convert the subdomain of a url into...
hooleylist
Feb 28, 2007Cirrostratus
You can get or set the HTTP host using HTTP::host. The URI can be gotten or set using HTTP::uri.
You can use getfield to pick out the parts of the host and then prepend them to the URI. You may want to add additional logic to handle the possibility that the host might not contain a string you want to prepend to the URI. For example, if a client requests http://www.example.com/someuri, you may not want to redirect them to http://example.com/www/someuri.
Here's an example to get you started:
when RULE_INIT {
Set the value for the domain with a leading period
We'll check the host header value for any string the comes before this string
and prepend it to the URI
set ::domain ".example.com"
}
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] ends with $::domain }{
Get any part of the host that comes before the domain.
Split the URI using the domain string. Grab the first string that comes before the domain
set subdomain [getfield [HTTP::host] $::domain 1]
If subdomain isn't null, prepend it to the URI
You could also add additional checks here like subdomain doesn't equal "www"
if { not ($subdomain == "") }{
HTTP::uri [concat "/$subdomain[HTTP::uri]"]
Set the HTTP host to the domain
HTTP::host [string range $::domain 1 end]
}
}
}
Edit: I forgot to change the host header to the domain only
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