Forum Discussion

zongfeng_101672's avatar
zongfeng_101672
Icon for Nimbostratus rankNimbostratus
Mar 29, 2012

[HTTP::uri] rewrite fail,help please ,thanks

my f5 has two pool, one pool name is test1, vip is 192.168.1.5 port 80; other pool name is test2,vip is 192.168.1.6 port 80

 

 

when user visit http://192.168.1.5/admin,I wish f5 dispatch this request to http://192.168.1.6/manager

 

 

i use iRule to control,but it's fail to redirect to other pool !

 

 

follow is my iRule:

 

 

when HTTP_REQUEST

 

{

 

log local0. "http uri before modified: [HTTP::uri]"

 

switch -glob [HTTP::uri] {

 

"/admin*" {

 

set uri value to a temporary variable

 

set tempuri [HTTP::uri]

 

log local0. "temprui before replace is $tempuri"

 

replace "/admin" to "/manager"

 

set tempuri [string replace $tempuri 0 5 "/manager"]

 

log local0. "tempuri after replace is $tempuri"

 

HTTP::uri $tempuri

 

log local0. "http uri after modified: [HTTP::uri]"

 

pool test2 }

 

default { pool test1}

 

}

 

}

 

 

follow is f5 log:

 

Thu Mar 29 15:24:03 CST 2012 info local/tmm tmm[3466] Rule adc : temprui before rewrite is /admin

 

Thu Mar 29 15:24:03 CST 2012 info local/tmm tmm[3466] Rule adc : tempuri after rewrite is /manager

 

Thu Mar 29 15:24:03 CST 2012 info local/tmm tmm[3466] Rule adc : after replace uri is /admin

 

3 Replies

  • Hi Zongfeng,

    Up until 11.0, the values for HTTP::path, HTTP::uri and other commands are cached within the same iRule event priority even if you modify them. The values are still changed for the request though. So what you're seeing is expected even though the URI has been updated. You can verify this by logging the values in a later HTTP_REQUEST event using priority:

    
    when HTTP_REQUEST priority 501 {
       log local0. "Updated URI in 501: [HTTP::uri]"
    }
    

    Here is a list of at least some of the HTTP:: commands which are cached:

    HTTP::password

    HTTP::username

    HTTP::host

    HTTP::path

    HTTP::query

    HTTP::request_num

    HTTP::status

    HTTP::uri

    HTTP::is_keepalive

    HTTP::is_redirect

    HTTP::request

    Again this was fixed in 11.0 so the return values are updated when they're changed.

    Aaron
  • hi , hoolio

     

    thanks for replay!

     

    the script in version 10 verification through, but in the version 9 can't redirect to pool test2, what is the problem? thanks!
  • have you done what Aaron suggested? what is the result in v9? you may add more log command.

    e.g.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set orguri [HTTP::uri]
       log local0. "http uri before modified: $orguri"
       switch -glob [HTTP::uri] {
          "/admin*" {
             set tempuri [HTTP::uri]
             log local0. "temprui before replace is $tempuri"
    
             set tempuri [string replace $tempuri 0 5 "/manager"]
             log local0. "tempuri after replace is $tempuri"
    
             HTTP::uri $tempuri
             pool test2
          }
          default {
             pool test1
          }
       }
    }
    
    when HTTP_REQUEST priority 501 {
            set newuri [HTTP::uri]
            log local0. "Updated URI in 501: $newuri"
    }
    
    when SERVER_CONNECTED {
            log local0. "[IP::client_addr]:[TCP::client_port]|[IP::local_addr clientside]:[TCP::local_port clientside]|$orguri|[LB::server pool]|[IP::remote_addr]:[TCP::remote_port]|$newuri"
    }
    }
    [root@ve1023:Active] config  b pool test2 list
    pool test2 {
       members 200.200.200.102:80 {}
    }
    
    [root@ve1023:Active] config  cat /var/log/ltm
    Apr  5 21:54:49 local/tmm info tmm[4797]: Rule myrule : http uri before modified: /admin123
    Apr  5 21:54:49 local/tmm info tmm[4797]: Rule myrule : temprui before replace is /admin123
    Apr  5 21:54:49 local/tmm info tmm[4797]: Rule myrule : tempuri after replace is /manager123
    Apr  5 21:54:49 local/tmm info tmm[4797]: Rule myrule : Updated URI in 501: /manager123
    Apr  5 21:54:49 local/tmm info tmm[4797]: Rule myrule : 172.28.19.80:33410|172.28.19.79:80|/admin123|test2|200.200.200.102:80|/manager123