Forum Discussion

Glen_33414's avatar
Glen_33414
Icon for Nimbostratus rankNimbostratus
Feb 13, 2013

This should be easy

Okay, I am a total noob here and I'm trying to figure out my first iRule. I've spent the better part of yesterday looking for examples to plagiarize and I found one that looked perfect for what I am wanting to do but it doesn't seem to work for me.

 

Go easy on me because I am sure this is the worst way to do this but okay.

 

What I have is a single VIP that goes to five different pools based on part of the URL. However, I want to strip out part of the URL before sending it to the pools.

 

So my URLs are basically this:

 

receptionservice.company.com/hangar1/services/reception

 

receptionservice.company.com/hangar2/services/reception

 

receptionservice.company.com/hangar3/services/reception

 

receptionservice.company.com/hangar4/services/reception

 

receptionservice.company.com/hangar5/services/reception

 

I want to strip out the /hangar out of the URL.

 

My first try was I build five HTTP Class Profiles to look at the pattern string for the "/hangar" part and for when it sees the correct hangar, send it to the pool that matches (the pools are called hangar1 through hangar5, just so you know).

 

That didn't work because the server folks are not expecting nor do they want to deal with the /hangar part of the URL - they only want what follows.

 

So I added to my HTTP Class Profiles with that option at the very bottom - Rewrite URI. I thought I was brilliant. Except that the URL can var after the "/services" part, sometimes they want "/reception" sometimes they want "/reception?wsdl". It doesn't seem like the the Rewrite URI option allows for the * wildcard - at least I couldn't get it to work.

 

Anyway, now I am thinking of an iRule. Here is what I have:

 

 

when HTTP_REQUEST {

 

log local0. "Initial [HTTP::uri]"

 

Check the HTTP path with wildcards

 

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

 

/hangar?/HTTP::uri "[HTTP::uri]"

 

}

 

log local0. "Rewritten [HTTP::uri]"

 

}

 

 

Here are the log results:

 

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm1 tmm1[8353] Rule URL_rewrite_Hangar : Rewritten /hanger2/services/reception

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm1 tmm1[8353] Rule URL_rewrite_Hangar : Initial /hanger2/services/reception

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm tmm[8352] Rule URL_rewrite_Hangar : Rewritten /hanger2/services/reception

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm tmm[8352] Rule URL_rewrite_Hangar : Initial /hanger2/services/reception

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm1 tmm1[8353] Rule URL_rewrite_Hangar : Rewritten /hanger2/services/reception

 

Wed Feb 13 07:22:49 CST 2013 info local/tmm1 tmm1[8353] Rule URL_rewrite_Hangar : Initial /hanger2/services/reception

 

 

 

Any idea what I am missing?

 

 

Thanks!

 

 

 

2 Replies

  • e.g.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.252:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
      if {[scan [HTTP::path] {/hangar%d} num] == 1} {
        switch $num {
          1 { node 200.200.200.101 }
          2 { node 2.2.2.2 }
          3 { node 3.3.3.3 }
          4 { node 4.4.4.4 }
          5 { node 5.5.5.5 }
          default {
             do something
          }
        }
        HTTP::uri [string map "/hangar$num/ /" [HTTP::uri]]
      } else {
         do something
      }
    }
    }
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.19.251(49995) <-> 172.28.19.252(80)
    1360764488.7196 (0.0010)  C>S
    ---------------------------------------------------------------
    GET /hangar1/services/reception HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Accept: */*
    Host: receptionservice.company.com
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(49995) <-> 200.200.200.101(80)
    1360764488.7207 (0.0010)  C>S
    ---------------------------------------------------------------
    GET /services/reception HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Accept: */*
    Host: receptionservice.company.com
    
    ---------------------------------------------------------------