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.” }{
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.
With my http::redirect statement, the site constantly just redirects, instead of allowing the server to post content back to the browser. It does this with both web servers, which are completely different types of services obviously.
Can anyone offer their ideas on logic that would make this work?
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"
}