Forum Discussion

Almassud_221797's avatar
Nov 08, 2015
Solved

if http uri starts with

Good morning all,

 

by no means an iRule expert, but I spend a good bit of time on google before posting.

 

the situation here is that I have this irule, which I am building upon at this point, but right now it reacts based on what the uri starts with. in most cases this works great without any issues, except this case there's a little twist, which is mid portion of the irul with the /string3.

 

the problem is that string3 is being used as a way for the irule to identify the uri and work with it, but it's really not part of the actual url. I know you're then why are you using it, Right?

 

the url is configured within the web.config, which has few of those and I am working with them one by one. the reason it's been working with the other ones is that they actually have something after / that I can work with while this one doesn't so I had to make something up.

 

so is there a way to make this irule work as is but make it remove /string3 before sending it to the browser?

 

when HTTP_REQUEST { if { [HTTP::uri] starts_with "/String1" or [HTTP::uri] starts_with "/String2" } { HTTP::header replace Host "host.domain.com" pool Pool1 } if { [HTTP::uri] starts_with "/string3" } { HTTP::header replace Host "host.domain.com" pool Pool2 } else { pool Pool3 } }

 

  • Thank you sir.

     

    I ended up having our dev team make a change so that I can have a single website with a virtual directory for each website and that worked well.

     

    Thanks all. MJ

     

5 Replies

  • Lucas_Thompson_'s avatar
    Lucas_Thompson_
    Historic F5 Account
    This is the connection chain here: 1. Client does handshake and transmits HTTP request to BIG-IP. It has a Host header and a Request-URI. 2. HTTP_REQUEST fires. 3. Your irule runs, switches the BIG-IP pool based on the Request-URI and sometimes rewrites the Host header from the client's request. 4. The request is transmitted to the web server. 5. Response from the web server is sent back to the client. Note that the Request-URI and Host header in the request are not part of it. Be aware here that the client doesn't actually have any idea that the irule is doing this. You have to decide what you want the Host header and Request-URI to contain at the time that the server receives it. A Request-URI must contain *something*, it can't be blank. If it's empty (ie, you visit "http://site.com" instead of "http://site.com/foo"), the browser will send a Request-URI of "/". If you want to manipulate the Request-URI to be "/", you can just set it like: HTTP::uri "/"
  • lthompson,

     

    Thanks for responding to my question.

     

    I just tried using "/", but this breaks everything, so I am going to have to be specific somehow

     

  • I guess I had to change strategy in hope that I could get the desired result differently. so I changed the iRule to look like this: when HTTP_REQUEST { if { [HTTP::uri] starts_with "/uri1" or [HTTP::uri] starts_with "/uri2" } { HTTP::header replace Host "host1.DomainName.com" pool Pool1 } if { [HTTP::host] equals "OldHost1" } { HTTP::header replace Host "NewHost1"

     

    pool Pool2 } if { [HTTP::host] equals "OldHost2" } { HTTP::header replace Host "NewHost2"

     

    pool Pool3 } else { pool Pool3 } }

     

    now the problem is that the iRule is not replacing the host as instructed and in fact it's not doing anything at all, which is odd.

     

    any help with this is greatly appreciated.

     

    • Mike_vill_16421's avatar
      Mike_vill_16421
      Icon for Nimbostratus rankNimbostratus
      Hi Almassud, I recommend that you use the [string tolower [HTTP::uri]] sentence when comparing, then use the log local. command to be sure that the request isn't matching in various if sentences, perhaps elseif use is better.
  • Thank you sir.

     

    I ended up having our dev team make a change so that I can have a single website with a virtual directory for each website and that worked well.

     

    Thanks all. MJ