Forum Discussion

James_Millsap_4's avatar
James_Millsap_4
Icon for Nimbostratus rankNimbostratus
Jun 24, 2013

Traffic routing with iRules

Ok, some time ago we started a project to move our extremely large websites to a new platform. Instead of rewriting them all, the would be slowly rolled out. This worked fine for subdirectories under www, but when the same method was wanting to be employed on other subdomains, the one iRule kinda broke down. Not being an expert, just a long time dabbler, I am trying to maybe get some tips on how such a thing should be done. Right now, we have about a dozen subdomains all passing through the same LTM VS. We have two web server pools, one for legacy, and one for new. May be easier to show an example....

 

 

 

Route the request to either the old web server or the new one depending on the URL

 

when HTTP_REQUEST {

 

 

Static variables

 

 

set HTTP_pool "legacy"

 

set HTTP_prod_pool "new_prod"

 

 

if { [string tolower [HTTP::host]] eq "testwww.example.com"} {

 

pool $HTTP_pool

 

} else {

 

switch -glob [string tolower [HTTP::uri]] {

 

"/supra {

 

pool $HTTP_pool

 

}

 

"/seo" {

 

pool $HTTP_pool

 

}

 

"/staff" {

 

pool $HTTP_pool

 

}

 

"/marketing" {

 

pool $HTTP_pool

 

}

 

default {

 

pool $HTTP_prod_pool

 

}

 

}

 

}

 

}

 

 

 

 

So that will work fine for testwww, but I would like to have other subdomains to be processed by the same iRule. I suppose I am just wondering if this is possible.

 

 

Thanks in advance,

 

5 Replies

  • The -glob option allows you to use wildcards in the evaluation, so assuming the URI is something more, for example, than "/marketing", you'd use "/marketing*" to indicate the URI starts with "/marketing".

     

     

    Also, just to be clear, you're evaluating the host name in the first section and the URI in the second. Does that mean that any request that isn't for "testwww.example.com" will have a specific application URI associated with it? It may be easier to assign each application its own host name, create DNS entries for each to point to the same VIP, and then use an [HTTP::host]-based evaluation for everything.
  • Yep, I use wildcards in the version of this that is in production right now. I think the main idea is that only specifically listed URI's will get routed to the legacy web server. My hope was to be able to add some of the other subdomains they want to use, such as email.example .com, in the same irule. I suppose I could add a new VS for each subdomain.

     

     

    Thanks for the help.
  • When you say "subdomain", are you referring to subdomains of example.com? (ex. email.example.com, www.example.com, testwww.example.com, etc.)? Can I also assume that the URIs (/supra, /seo, /staff, and /marketing) exist for all applications? If so, then something like this perhaps:

    
    when HTTP_REQUEST {
         set hostlist [list email.example.com www.example.com test.example.com test1.example.com]
    
         if { [string tolower [HTTP::host]] equals "testwww.example.com" } {
              pool $HTTP_pool
         } elseif { [lsearch $hostlist [string tolower [HTTP::host]]] ne -1 } {
              switch -glob [string tolower [HTTP::uri]] {
                   ...
              }
         }
    }
    
  • That is exactly what I mean. I think this will probably solve my issue. Let me fire up a new VS, and give it a try. I will let you know the result. Thanks!

     

  • Excellent this works really well. My only concern is if they have on separate subdomains duplicated URI's. like on one subdomain they want /index.html to be direct to the legacy server, but want it to go through to new production on another subdomain. Would something like this work?

    
    when HTTP_REQUEST {
         set hostlist1 [list email.example.com www.example.com test.example.com test1.example.com]
         set hostlist2 [list staff.example.com owa.example.com external.example.com test2.example.com]
        
         if { [string tolower [HTTP::host]] equals "testwww.example.com" } {
              pool $HTTP_pool }
         elseif { [lsearch $hostlist1 [string tolower [HTTP::host]]] ne -1 } {
              switch -glob [string tolower [HTTP::uri]] {
                   ...
              }
         }    
         elseif { [lsearch $hostlist2 [string tolower [HTTP::host]]] ne -1 } {
              switch -glob [string tolower [HTTP::uri]] {
                   ...
              }
         }    
    }
     

    Not sure, what do you think?