Forum Discussion

Matt_Mueller_10's avatar
Matt_Mueller_10
Icon for Nimbostratus rankNimbostratus
Oct 23, 2008

Help - 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

 

}

 

}

2 Replies

  • 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?

     

     

    Basically, for newbie user who just types in subdomain1.newdomain.com I want to put in logic to nicely redirect them to https://subdomain1.newdomain.com/virtualdir to make things simple.

     

     

    when HTTP_REQUEST {

     

     

    Checks the URI and forces to all lowercase for the check first for subdomain1

     

    if { [string tolower [HTTP::host]] equals "subdomain1.newdomain.com" }{

     

    HTTP::redirect "https://subdomain1.newdomain.com/virtualdir/"

     

    pool subdomain1

     

    Checking if URI starts with ftp

     

    } elseif { [string tolower [HTTP::host]] equals "ftp.newdomain.com" }{

     

    HTTP::redirect "https://ftp.newdomain.com"

     

    pool newdomainftp

     

    All non-matching URIs

     

    } else {

     

    pool errorpage

     

    }

     

    }
  • 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"  
     } 
     

    Aaron