Forum Discussion

kupaloid_50119's avatar
kupaloid_50119
Icon for Nimbostratus rankNimbostratus
Oct 05, 2011

Dynamic redirect

Hi, I am a newbie to irule and can only do basic redirect. But we have a requirement for dynamic redirect. Can someone help?

 

 

 

http://www.abc.com/test/[placeholder]

 

permanent redirect to

 

http://abc.123.net/dc?purl=[placeholder]

 

 

 

For example:

 

http://www.abc.com/test/abc should be redirected to

 

http://abc.123.net/dc?purl=abc

 

 

 

Thanks

 

5 Replies

  • [root@tulip:Active] config  b virtual bar list
    virtual bar {
       destination 172.28.17.66:http
       ip protocol tcp
       rules myrule
       profiles
          http
          tcp
    }
    [root@tulip:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]"
    }
    }
    [root@tulip:Active] config  curl -I http://www.abc.com/test/abc
    HTTP/1.0 302 Found
    Location: http://abc.123.net/dc?purl=abc
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Thanks Nitass for the quick reply. I need to match http://www.abc.com/test/ since several irules are applied on the vip. What should be my match statement?

     

     

    rule myrule {

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::uri]] starts_with "/test"} {

     

    HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" }

     

    }

     

    }

     

     

  • that's fine.

    [root@tulip:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
          if {[string tolower [HTTP::uri]] starts_with "/test"} {
             HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" }
       }
    }
    
    [root@tulip:Active] config  curl -I http://www.abc.com/aaaaaa/bbbbb/cccccc
    curl: (52) Empty reply from server
    
    [root@tulip:Active] config  curl -I http://www.abc.com/test/abc
    HTTP/1.0 302 Found
    Location: http://abc.123.net/dc?purl=abc
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • or if u wanna match host name as well.

    rule myrule {
       when HTTP_REQUEST {
          if {[string tolower [HTTP::host]] equals "www.abc.com" and [string tolower [HTTP::uri]] starts_with "/test"} {
             HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]"
          }
       }
    }