redirect based on Source IP

Good day all. Looking to write efficient iRule (many intranet clients, processing is important) Logic as follows: if client coming from private network(10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) serve content over http else (client coming from Internet) redirect to SSL offloaded content from same pool.

any recommendations?

Thanks in advance.

first, create a datagroup with the rfc1918 space

ltm data-group internal rfc1918 {
    records {
        10.0.0.0/8 { }
        172.16.0.0/12 { }
        192.168.0.0/16 { }
    }
    type ip
}

then you can use this iRule

when HTTP_REQUEST {
  if { ! [class match [IP::client_addr] equals "rfc1918" ] } {
    HTTP::redirect "https://[HTTP::host][HTTP::uri]"
  }
}

appriciate, worked as advertized!