domain

Description

A custom iRule function which parses the specified string as a dotted domain name and returns the last portions of the domain name.

Syntax

domain <string> <count>

domain <string> <count>

  • Parses the specified string as a dotted domain name and returns the last <count>* portions of the domain name.

Examples

when HTTP_REQUEST
   if { [HTTP::uri] ends_with ".html" } {
      pool cache_pool
      set key [crc32 [concat [domain [HTTP::host] 2] [HTTP::uri]]]
...

This code:
log local0. [domain www.sub.my.domain.com 1]   ; # result: com
log local0. [domain www.sub.my.domain.com 2]   ; # result: domain.com
log local0. [domain www.sub.my.domain.com 3]   ; # result: my.domain.com
log local0. [domain www.sub.my.domain.com 4]   ; # result: sub.my.domain.com
log local0. [domain www.sub.my.domain.com 5]   ; # result: www.sub.my.domain.com
log local0. [domain www.sub.my.domain.com 6]   ; # result: www.sub.my.domain.com

This code:
log local0. [domain www.sub.my.domain.co.uk 1]   ; # result: uk
log local0. [domain www.sub.my.domain.co.uk 2]   ; # result: co.uk
log local0. [domain www.sub.my.domain.co.uk 3]   ; # result: domain.co.uk
log local0. [domain www.sub.my.domain.co.uk 4]   ; # result: my.domain.co.uk
log local0. [domain www.sub.my.domain.co.uk 5]   ; # result: sub.my.domain.co.uk
log local0. [domain www.sub.my.domain.co.uk 6]   ; # result: www.sub.my.domain.co.uk

(* A bug in v9.1.0 truncates last character if = 1 or 2.)