Forum Discussion

Roflcopter's avatar
Roflcopter
Icon for Nimbostratus rankNimbostratus
Nov 26, 2013

iRule append URi based on URL

I am looking to create an iRule that will append the URI based on the subdomain called.

 

For example - if exmaple1.test.com append /example1 if example2.test.com append /example2

 

I assume this is pretty basic to do but I am really lost once it comes to correct syntax etc for programming.

 

Any help much appreciated.

 

Cheers,

 

Isaac

 

4 Replies

  • This is quite simple - it will append the host header to the original URL. You can split up the host header with getfield eg set append [getfield [HTTP::host] "." 1]

    when HTTP_REQUEST {
        set original_uri [HTTP::uri]
        set append [HTTP::host]
        set HTTP::uri "$original_uri/$append"
    }
    
  • when HTTP_REQUEST {
        set original_uri [HTTP::uri]
        set append [getfield [HTTP::host] "." 1]
        set HTTP::uri "$original_uri/$append"
    }
    
  • You seem to have used switch with else here, and two "when HTTP_REQUEST"s. Might be best to write this in pseudocode first and build the syntax from there. Does this match what you want?

    when HTTP_REQUEST {
        if HTTP::host == owamail.test.com.au                
            then set HTTP::uri to /owa[HTTP::uri]
        elseif  HTTP::host == mobile.test.com.au                
            then set HTTP::uri to /Microsoft-Server-ActiveSync[HTTP::uri]
        endif
    }
    
  • OK, so this is the iRule that implements that pseudocode:

    when HTTP_REQUEST {
        if { [HTTP::host] equals "owamail.test.com.au"} {               
            set HTTP::uri /owa[HTTP::uri]
        } elseif  { [HTTP::host] equals "mobile.test.com.au"} {                
            set HTTP::uri /Microsoft-Server-ActiveSync[HTTP::uri]
        } 
    }