Forum Discussion
Matt_Mueller_10
Nimbostratus
Oct 23, 2008Help - starts_with subdomain pool routing?
I'm trying to write an irule that will pool information based on the incoming subdomain\domain used. For example, domain1 will have many subdomains, can I route the traffic to a desired pool based off the incoming subdomain\domain specified? Note my requests are coming in over HTTPS. What I am trying to accomplish is someone coming in over https://subdomain1.newdomain.com/virtualdirectory/ be routed to the appropriate pool in the background, and holding the virtual directory they specified. Right now requests are just going to the pool "errorpage" See my example below
when HTTP_REQUEST {
Checks the URI and looks for subdomain1
if { [string tolower [HTTP::uri]] starts_with "subdomain1." }{
pool subdomain1
Check the URI and look for subdomain2
} elseif { [string tolower [HTTP::uri]] starts_with "subdomain2." }{
pool subdomain2
All non-matching URIs
} else {
pool errorpage
}
}
- Matt_Mueller_10
Nimbostratus
Well, I got this part of it to work by using the HTTP::host with equals, however I'm struggling with how to auto redirect to a particular virtual directory. - hoolio
Cirrostratus
Maybe something like this? I'm not sure if you're using this rule on an HTTPS VIP which ftp.newdomain.com resolves to or not. If you do, then you shouldn't redirect requests made to ftp.newdomain.com with a uri of / to https://ftp.newdomain.com/ or you'll get a redirect loop.when HTTP_REQUEST { log local0. "[IP::client_addr]:TCP::client_port]: New request to [HTTP::host], [HTTP::uri]" Checks the URI and forces to all lowercase for the check first for subdomain1 switch [string tolower [HTTP::host]] { "subdomain1.newdomain.com" { if { [HTTP::path] eq "/"}{ log local0. "[IP::client_addr]:TCP::client_port]: Matched subdomain1.newdomain.com with URI of /. Redirecting to https" HTTP::redirect "https://subdomain1.newdomain.com/virtualdir/" return } else { log local0. "[IP::client_addr]:TCP::client_port]: Matched subdomain1.newdomain.com with URI not /. Using pool subomain1" pool subdomain1 return } } "ftp.newdomain.com" { if { [HTTP::path] eq "/"}{ log local0. "[IP::client_addr]:TCP::client_port]: Matched ftp.newdomain.com with URI of /. Redirecting to https" HTTP::redirect "https://ftp.newdomain.com/new_uri/" return } else { log local0. "[IP::client_addr]:TCP::client_port]: Matched ftp.newdomain.com with URI not /. Using pool newdomainftp" pool newdomainftp return } } } If we got here, no condition was matched, so use default pool pool errorpage log local0. "[IP::client_addr]:TCP::client_port]: No match. Using default pool" }
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