Forum Discussion

MihirP1208_3846's avatar
MihirP1208_3846
Icon for Nimbostratus rankNimbostratus
Feb 25, 2019

taking value and append to uri while masking?

Hello F5 community:

 

Is there such a way to create an irule which will take the value before the domain, *.test123.com, append it to ) and pull up the contents without changing the URL in the browser?

 

 

for example. A user types in help.test123.com in the browser, but it will pull up the site contents from without changing the URL in the browser.

 

  • I was able to find the first part on DevCentral forum of which it takes the value before the domain and adds as uri for testing purposes, however I get the following error when I try to save it.

    01070151:3: Rule [/Common/ddc-wpchange1.com_irule] error: /Common/ddc-wpchange1.com_irule:8: error: [parse error: PARSE syntax 289 {syntax error in expression " [string tolower [HTTP::host]] ends with $::domain ": extra tokens at end of expression}][{ [string tolower [HTTP::host]] ends with $::domain }] /Common/ddc-wpchange1.com_irule:21: error: [wrong args][HTTP::host [string range $::domain 1 end]]

    when RULE_INIT { Set the value for the domain with a leading period We'll check the host header value for any string the comes before this string and prepend it to the URI set ::domain ".test123.com" } when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends with $::domain }{

       Get any part of the host that comes before the domain.
         Split the URI using the domain string.  Grab the first string that comes before the domain
      set subdomain [getfield [HTTP::host] $::domain 1]
    
       If subdomain isn't null, prepend it to the URI 
         You could also add additional checks here like subdomain doesn't equal       "www"
      if { not ($subdomain == "") }{
    
     HTTP::uri [concat "/$subdomain[HTTP::uri]"]
    
          Set the HTTP host to the domain
         HTTP::host [string range $::domain 1 end]
      }
    

    } }

  • I was able to get it to work using the following syntax:

    when HTTP_REQUEST { Check for a non-null length host header if {[string match {[a-zA-Z]} [HTTP::host]]}{

       Use string commands to parse the subdomain
      set subdomain [string range [HTTP::host] 0 [expr {[string first . [HTTP::host]] -1}]]
    
       Use the getfield command to parse the subdomain
      set subdomain [getfield [HTTP::host] . 1]
    
       Use scan to parse the subdomain
      scan [HTTP::host] {%[^.]} subdomain
    
        HTTP::header replace Host "www.test123.com"
        HTTP::uri /$subdomain[HTTP::uri]
    

    } }

  • Simpler code :

     

    when HTTP_REQUEST { 
         Check for a non-null length host header 
        if {[string match {[a-zA-Z]} [HTTP::host]]} {
            HTTP::host "www.test123.com"
            HTTP::uri /[getfield [HTTP::host] . 1][HTTP::uri]
        }
    }