Forum Discussion

Jeff_46763's avatar
Jeff_46763
Icon for Nimbostratus rankNimbostratus
Sep 11, 2012

Redirect Irule for wildcard URL's

Hi all, Im working on creating an Irule for a URL that I want anything that ends in .dmz.com and .com to go to a certain URL. I attemped doing a .*, but that didn't work so well. Here's what I have if someone could please help. Im looking to redirect anything ending in .com and .lb-devdmz.abbott.com to go to the below URL.....Appreciate it.

 

 

when HTTP_REQUEST {

 

if {[string tolower [HTTP::host]] ends_with ".com"} {

 

HTTP::redirect "]"

 

}

 

}

 

  • both of those host values end with ".com", so your rule should work.

     

    Otherwise, you can use an 'or' statement in the if clause:

     

     

    if { ( condition ) or ( condition ) } {...

     

  • Here are a couple of options:

    
    when HTTP_REQUEST {
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
    if {[string tolower [HTTP::host]] starts_with "abbott."} {
    HTTP::redirect "http://abbottace-d.com[HTTP::uri]"
    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://abbottace-d.com[HTTP::uri]"
    }
    }
     Or
    when HTTP_REQUEST {
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
    switch -glob [string tolower [HTTP::host]] {
    "abbott.*" -
    "*.lb-devdmz.abbott.com" {
    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://abbottace-d.com[HTTP::uri]"
    HTTP::redirect "http://abbottace-d.com[HTTP::uri]"
    }
    }
    }
    

    Aaron