Forum Discussion

Earnest_Dyke_10's avatar
Earnest_Dyke_10
Icon for Nimbostratus rankNimbostratus
Feb 16, 2006

Simple IRule apparently not working

Greegings all.

We have the IRule below and when we install it and attempt to execute our web app, we see not messages in the log. We do not see any syntax errors messages either. Any ideas why we would be getting no output at all?

Thanks in advance for any and all help!

Earnie!

  when RULE_INIT {
    log local0. "Earnies rule is being initialized"
  }
  when HTTP_REQUEST {
 Look of each entry in badurl in the URI
    set uri [HTTP::uri]
    log local0. "Checking uri: $uri"
    set badurl [list "http://ww1:80" "https://ww1:80"]
    foreach x $badurl {
      if {$uri starts_with $x} {
        set len [string length $x]
 Get all of the URI after the port number
        set resource [substr $uri $len]
        set outlocation "https://ww1$resource"
        log local0. "Changing request for $uri to $outlocation"
        HTTP::uri $outlocation
        break;
      }
    }
    
  }
  when HTTP_RESPONSE {
 If this is not a browser redirect, igonore it
    if {[HTTP::status] starts_with "3"} {
      set location [HTTP::header "Location"]
      if {$location == ""} {
        return
      }
    } else {
      return
    }
  
    log local0. "Checking location: $location"
 Look of each entry in badurl in the redirect location
    set badurl [list "http://ww1:80" "https://ww1:80"]
    foreach x $badurl {
      if {$location starts_with $x} {
        set len [string length $x]
 Get all of the URI after the port number
        set resource [substr $location $len]
        set outlocation "https://ww1$resource"
        log local0. "Rewriting $location to $outlocation"
        HTTP::header replace "Location" $outlocation
        break;
      }
    }
  }