Forum Discussion

mikegray_198028's avatar
Jan 04, 2017

irule help

Hello Team,

I am using the following irule to route traffic directly to the node based uri

https://example.com/app/* > node 192.168.10.20 port 80

https://example.com/* > default pool.

This is working but while accessing /app/ ltm not sending response with /app/ example GET https://example.com/app/test/index.html response 302 https://example.com/test/login.html

Hence the next request going to the default pool instead of direct node . can we modify the response to add /app/

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri] ] starts_with "/app/" } {
    node 192.168.10.20 80
    HTTP::uri [string map -nocase {"/app/" "/"} [HTTP::uri]]
  }
}

5 Replies

  • You need to rewrite the redirect

    if {[HTTP::is_redirect]} {
        HTTP::header replace Location [string map -nocase "https://example.com/test https://example.com/app/test" [HTTP::header Location]]
    }
    
  • Pete,

     

    I am getting error: [command is not valid in the current scope][

    But please note that we are getting 302 from the server response to ltm

     

  • Sorry, I should have mentioned that this is relevant in the HTTP_RESPONSE event, not the HTTP_REQUEST event. Add this to the bottom of the existing iRule and it should be fine.

    when HTTP_RESPONSE {
        if {[HTTP::is_redirect]} {
            HTTP::header replace Location [string map -nocase "https://example.com/test     https://example.com/app/test" [HTTP::header Location]]
        }
    }
    
  • OK, let's add some debugging logs to see what's happening:

    when HTTP_REQUEST {
        log local0. "Request from [IP::client_addr] URI: [HTTP::uri]"
        if { [string tolower [HTTP::uri] ] starts_with "/app/" } {
            node 192.168.10.20 80
            HTTP::uri [string map -nocase {"/app/" "/"} [HTTP::uri]]
            log local0. "Request from [IP::client_addr] URI: [HTTP::uri] matched /app"
        }
     }
    when HTTP_RESPONSE {
        log local0. "Response to [IP::client_addr] Status: [HTTP::status]"
        if {[HTTP::is_redirect]} {
            log local0. "Response to [IP::client_addr] original Location: [HTTP::header Location]"
            HTTP::header replace Location [string map -nocase "https://example.com/test     https://example.com/app/test" [HTTP::header Location]]
            log local0. "Response to [IP::client_addr] modified Location: [HTTP::header Location]"
        }
    }