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 a directory name that it passed through to the webserver like this.
subdomain.domain.com -> F5 box -> webserver/subdomain
I cannot find how to extract the subdomain and use it as a variable to generate the request that is sent to the webserver.
If anyone knows how this could be done or if there are any tutorials that they could point me towards that would be most appreciated.
many thanks
Simon
- hooleylistCirrostratusYou can get or set the HTTP host using HTTP::host. The URI can be gotten or set using HTTP::uri.
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] } } }
- Simon_Wright_85NimbostratusHi 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