Forum Discussion

PacketHead_4009's avatar
PacketHead_4009
Icon for Nimbostratus rankNimbostratus
Dec 14, 2011

Simple iRule with Sticky?

Hello,

 

 

I'm trying to create what I think is a fairly simple iRule:

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/sites/tech*" } {

 

pool Tech_Web_Pool_80

 

} else {

 

pool Main_Web_Pool_80

 

}

 

}

 

 

 

 

The issue I have is that the first part of the iRule works. It sends you to the right web pool but the page is missing content because it is trying to load jpegs, png files, and gifs for the buttons etc ... These graphic files are in the /main/images folder which due to iRule above gets sent to the other pool.

 

 

 

Is there a way so that if it matches the first part of the iRule and goes to my Tech_Web_Pool_80 that it then forces the client to retrieve all content and links from that pool?

 

 

 

The main problem is that the /main/images directory exists in both pools but the graphic images are completely different since they are on different versions of our website.

 

 

 

Any help would be appreciated!

 

 

 

Thanks!

 

 

 

James

 

 

 

  • Hi James,

    You might be able to check the Referer header to see if the request came from a /sites/tech request:

    
    when HTTP_REQUEST {
      if { [HTTP::uri] contains "/sites/tech" or [HTTP::header Referer] contains "/sites/tech" } {
        pool Tech_Web_Pool_80
      } else {
        pool Main_Web_Pool_80
      }
    }
    

    If that doesn't work, the simplest fix from an LTM perspective would be to modify the app versions to use content from separate directories.

    Aaron
  • Thanks Hoolio. I'm unfamiliar with the Referer command. Will this keep that users session all on the Tech_Web_Pool_80 including the request for the images in the other directory?

     

     

    Also, two other questions:

     

     

     

    1.) How do I get it so that it is all non-case sensitive? Right now it doesn't honor sites/Tech or Sites/tech.

     

     

     

    2.) And if I have another URL I need to send same Tech Web Pool (say sites/dev) how do I enter it in the iRule so that it will search both before sending to default/else pool?

     

     

    Thanks again,

     

     

    James

     

     

  • Browsers can set the Referer header to indicate which URI generated the current request:

    http://tools.ietf.org/html/rfc2616section-14.36
    
       The Referer[sic] request-header field allows the client to specify,
       for the server's benefit, the address (URI) of the resource from
       which the Request-URI was obtained (the "referrer", although the
       header field is misspelled.) The Referer request-header allows a
       server to generate lists of back-links to resources for interest,
       logging, optimized caching, etc. It also allows obsolete or mistyped
       links to be traced for maintenance. The Referer field MUST NOT be
       sent if the Request-URI was obtained from a source that does not have
       its own URI, such as input from the user keyboard.
    
    http://tools.ietf.org/html/rfc2616section-15.1.3
    
       Clients SHOULD NOT include a Referer header field in a (non-secure)
       HTTP request if the referring page was transferred with a secure
       protocol.
    

    Here's an example which checks the URI and then the Referer header for multiple case insensitive patterns. Make sure to put the patterns in lower case as the URI and Referer header are set to lower case for the comparisons.

    when HTTP_REQUEST {
     Check the requested URI to see if it is a non-default pool request
    switch -glob [string tolower [HTTP::uri]] {
    "*/sites/tech*" -
    "*/uri2/tech*" -
    "*/uri3/tech*" {
    pool Tech_Web_Pool_80
    }
    default {
     No match on the URI, so check the Referer header 
     to see if it is a non-default pool request
    switch -glob [string tolower [HTTP::header Referer]] {
    "/sites/tech" -
    "*/uri2/tech*" -
    "*/uri3/tech*" {
    pool Tech_Web_Pool_80
    }
    default {
     No match on URI or Referer so use the main pool
    pool Main_Web_Pool_80
    }
    }
    }
    }
    }
    

    Aaron
  • Nice, thanks Aaron. I was wondering if I was going to have to use glob. I will tweak this for the URIs that I have and see how it works. Thanks!
  • Also is there a reason why there are no asterisks on the "sites/tech" line in the Referer portion of the script?

     

     

    "/sites/tech" -

     

    "*/uri2/tech*" -

     

    "*/uri3/tech*" {
  • That was just a typo :) You'll want the wildcards for /sites/tech too.

     

     

    Aaron
  • Hello Aaron,

     

     

     

    Thanks I placed them in there as I figured they would be needed. All is working well except a few items:

     

     

     

    1.) I can't get to the main URL anymore http://mysite. I can browse to http://mysite/sites/tech but it isn't honoring http://mysite/default.aspx

     

     

     

    2.) What happens if I have a URL of /sites/technology that needs to go to the Main_Web_Pool_80? Won't the above rule for */sites/tech* automatically send it to the Tech_Web_Pool_80 pool? Do I simply remove the appending * after tech to make the entry more specific so that only /sites/tech would be sent to the Tech_Web_Pool_80?

     

     

     

    Any ideas? So far it is working great overall, thanks for the help!

     

     

     

    Regards,

     

     

     

    James

     

  • Hi James,

    I assume you want requests for / and /default.aspx to go to the Tech_Web_Pool_80 pool then?

    If you have specific exceptions for URIs you want to go to the main pool, you could try something like the example below to have them matched first. Note that I've added logic to parse the path and filename from the Referer header so you can check for / and /default.aspx there.

    when HTTP_REQUEST {
     Check the requested URI to see if it is a non-default pool request
    switch -glob [string tolower [HTTP::uri]] {
    "/sites/technology*" {
     Use the main pool
    pool Main_Web_Pool_80
    }
    "/" -
    "/default.aspx*" -
    "*/sites/tech*" -
    "*/uri2/tech*" -
    "*/uri3/tech*" {
    pool Tech_Web_Pool_80
    }
    default {
     No match on the URI, so check the Referer header 
     to see if it is a non-default pool request
    
     Use URI::path and URI::basename to get the URI from the Referer header
    set referer [string tolower [HTTP::header Referer]]
    switch -glob "[URI::path $referer][URI::basename $referer]" {
    "/sites/technology*" {
     Use the main pool
    pool Main_Web_Pool_80
    }
    "/" -
    "/default.aspx*" -
    "/sites/tech" -
    "*/uri2/tech*" -
    "*/uri3/tech*" {
    pool Tech_Web_Pool_80
    }
    default {
     No match on URI or Referer so use the main pool
    pool Main_Web_Pool_80
    }
    }
    }
    }
    }
    

    Aaron
  • Ok, I need to fire this thread up again. The script that Hoolio provided is working like a champ. Now we are migrating and we are hitting a small issue. First here is the modified version of his iRule:

     

    when HTTP_REQUEST {

     

    Check the requested URI to see if it is a non-default pool request

     

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

     

    "*/sites/webservices*" -

     

    "*/sites/humanresources*" -

     

    "*/sites/itplanning*" -

     

    "*/*" -

     

    "*/mysite*" {

     

    pool SP2003_Web_Pool_80

     

    }

     

     

    default {

     

    No match on the URI, so check the Referer header

     

    to see if it is a non-default pool request

     

    switch -glob [string tolower [HTTP::header Referer]] {

     

    "*/sites/webservices*" -

     

    "*/sites/humanresources*" -

     

    "*/sites/itplanning*" -

     

    "*/*" -

     

     

    "*/mysite*" {

     

    pool SP2003_Web_Pool_80

     

    }

     

     

    default {

     

    No match on URI or Referer so use the main pool

     

    pool SP2010_Web_Pool_80

     

    }

     

    }

     

    }

     

    }

     

    }

     

     

    So our plan is to migrate everything to the SP2010 web pool. We will accomplish this by removing one of the migrated sites from the iRule; for example "/sites/webservices". If we remove the line it will go to the default rule and go to the SP2010 web pool. Here is the issue. They plan to migrate the main page "/" and "/default.aspx" first. Here is the issue. For any sites that are NOT yet migrated and set to go to the SP2003 web pool when we click on the main intranet logo it tries to go back to our default page "/default.aspx". The problem is that it doesn't go to the SP2010 instance it stays on the SP2003 web pool. I'm guessing this is due to the referrer statement? Is there a better way to do this now that we are moving the main page first?

     

     

    Sorry for the long thread but this has me pulling my hair out. Thank you!

     

     

    - James