For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Snl's avatar
Snl
Icon for Cirrostratus rankCirrostratus
Oct 30, 2016

Irule Issue - url rewrite and redirect

I am trying to archive below but its not working

 

original request - https://abc.com/db/ap-webconsole before reach server it should go as https://abc.com:3333/ap-webconsole response should go as https://abc.com/ap-webconsole to client

 

Code
when HTTP_REQUEST { log local0. "Original path: [HTTP::path]"log local0. "Original uri: [HTTP::uri]"log local0. "host = [HTTP::host]; path = [HTTP::path]"
if { [HTTP::uri] starts_with "/db/ap-webconsole" } { 
    HTTP::path "[HTTP::host]:3333/ap-webconsole" log local0. "Pool app1 chosen" pool app1 log local0. "Modified uri: [HTTP::uri]"     } else { log local0. "Pool app2 chosen"        pool app2
} }

any help appreciated

 

Thanks snl

 

3 Replies

  • Hi,

    in your irule, you get request parameters with good command, but when you change it, you only modified HTTP::path...

    HTTP::host "[HTTP::host]:3333"
    HTTP::path "/ap-webconsole"
    

    another point is to replace /db/ap-webconsole with /ap-webconsole

    HTTP::path [string map {/db/ap-webconsole /ap-webconsole} [HTTP::path]]
    
  • Snl's avatar
    Snl
    Icon for Cirrostratus rankCirrostratus

    so can i try as below

     

    Code
    when HTTP_REQUEST {
    log local0. "Original path: [HTTP::path]"
    log local0. "Original uri: [HTTP::uri]"
    if { [HTTP::uri] starts_with "/db/ap-webconsole" }{ 
    HTTP::host "[HTTP::host]:3333"
    HTTP::path [string map {/db/ap-webconsole /ap-webconsole} [HTTP::path]]
    log local0. "Pool app1 chosen" 
    pool app1 
    log local0. "Modified uri: [HTTP::uri]"     }
    else {
    log local0. "Pool app2 chosen" 
     pool app2
    }
    }

    still i am getting error on line 5 , how we can modify the host with :3333 or use respond location 301 because backend http host is change to something else do i required to modify the response as well with stream profile ? pls assist

     

  • Hi,

    try this irule:

    when HTTP_REQUEST {
        switch -glob -- [HTTP::path] {
            "/db/ap-webconsole*" {
                HTTP::respond 301 noserver Location [string map {/db/ap-webconsole /ap-webconsole} [HTTP::uri]]
            }
            "/ap-webconsole*" {
                HTTP::header replace Host "[HTTP::host]:3333"
            }
            default {
                HTTP::respond 302 noserver Location "/ap-webconsole/"
            }
        }
    }