Forum Discussion

BaltoStar_12467's avatar
Nov 23, 2015

BIG-IP : irule syntax to construct url

F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi

Can anyone see a problem with syntax with this iRule :

when HTTP_REQUEST {
  set host [HTTP::host]
  if { not ([string tolower [HTTP::host]] starts_with "www.") } {
    set host "www.[HTTP::host]"
  }
  HTTP::redirect "https://$host[HTTP::uri]"
}

This irule lives on an http vip.

The intention is to prepend "www." to the host ( if not already present ).

2 Replies

  • eneR's avatar
    eneR
    Icon for Cirrostratus rankCirrostratus

    Syntax looks fine for me. 8|

     

    Write a

     

    log local0. "https://$host[HTTP::uri]"

     

    under the irule and check your logfile if the string looks like desired!

     

  • is it http or https virtual server?

    if http, it is okay but if https, it will cause redirection loop because HTTP::redirect is outside if-condition.

     configuration
    
    [root@ve11c:Active:In Sync] config  tmsh list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:443
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            clientssl {
                context clientside
            }
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 17
    }
    [root@ve11c:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      set host [HTTP::host]
      if { not ([string tolower [HTTP::host]] starts_with "www.") } {
        set host "www.[HTTP::host]"
      }
      HTTP::redirect "https://$host[HTTP::uri]"
    }
    }
    
     test
    
    [root@ve11c:Active:In Sync] config  curl -ik https://172.28.24.10 -H "Host: www.abc.com"
    HTTP/1.0 302 Found
    Location: https://www.abc.com/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0