Forum Discussion

Clint_Byrum_103's avatar
Clint_Byrum_103
Icon for Nimbostratus rankNimbostratus
Mar 16, 2006

Simple HTTP::uri rule doesn't work as expected

I'm very new to iRules, just got our LTM recently.

 

 

I setup a rule like this:

 

 

when HTTP_REQUEST {

 

if {[string tolower [HTTP::uri]] starts_with "/jsfeatured.php"} {

 

pool jsfeatured_pool_80

 

} elseif {[string tolower [HTTP::uri]] starts_with "/js.php"} {

 

pool jobsearch_pool_80

 

}

 

}

 

 

My goal here is simple. If the user requests /jsfeatured.php, send them to the jsfeatured pool. If they're requesting /js.php, send them to the jobsearch pool. Otherwise, let it fall through to the virtual server's default pool.

 

 

Whats happening is requests to

 

 

/texis/jobseeker/

 

 

Are ending up in the jsfeatured pool, when they have a Referer: header of http://xxxxxx/jsfeatured.php

 

 

This just doesn't seem like what I want _AT ALL_.

 

 

I tried making it

 

 

when HTTP_REQUEST {

 

if {[string tolower [URI::query [HTTP::uri]]] starts_with "/jsfeatured.php"} {

 

pool jsfeatured_pool_80

 

} elseif {[string tolower [HTTP::uri]] starts_with "/js.php"} {

 

pool jobsearch_pool_80

 

}

 

}

 

 

But that made the rule never match the /jsfeatured.php, sending all of that traffic through to the default pool.

 

 

Am I missing something here? It doesn't seem to me like HTTP::uri should be matching stuff in _any_ of the headers. I only want to match whats on that first line.

 

 

Thanks!

4 Replies

  • You are doing everything correctly and it should work. The value HTTP::uri does not contain any header values so odds are something else is amiss.

    I would start by throwing in some logging

    when HTTP_REQUEST {
     log local0. "Requested URI: [HTTP::uri]"
     if {[string tolower [HTTP::uri]] starts_with "/jsfeatured.php"} {
      log local0. "URI: [HTTP::uri] matched /jsfeatured.php"
      pool jsfeatured_pool_80
     } elseif {[string tolower [HTTP::uri]] starts_with "/js.php"} {
      log local0. "URI: [HTTP::uri] matched /js.php"
      pool jobsearch_pool_80
     } else {
      log local0. "URI: [HTTP::uri] not matched"
     }
    }

    Then look in the /var/log/ltm file and you'll see the output of the log messages. In most cases, watching the logic flow can help diagnosing these problems.

    Stupid question, but could the jsfeatured_pool_80 be the default pool for the virtual? If so, not overriding in the iRule would route there.

    -Joe
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    FYI - this is caused be keepalive requests... If you don't explicitly select the pool, the last pool selection stands. Since multiple requests, may come on the same connection, it's a good idea to always have an else clause to pick the default pool.

    Nope, you can grab the default pool and put it in a variable.
    when CLIENT_ACCEPTED {
      set default_pool [LB::server pool]
    }
    when HTTP_REQUEST {
      if {...} {
         pool a
      }
      elseif {...} {
         pool b
      }
      else {
         pool $default_pool
      }
    }