Forum Discussion

RSpangler_17032's avatar
RSpangler_17032
Icon for Nimbostratus rankNimbostratus
Mar 06, 2017

Remove ports from URL's

Hello,

I have the following iRule and it works as expected;

when HTTP_REQUEST {

  switch -glob [string tolower [HTTP::host]] {
 "www.company.com"      { pool company.com_www }
 "www2.company.com"     { pool company.com_www2 }
 "www3.company.com"     { pool company.com_www3 }
 "www4.company.com"     { pool company.com_www4 } 
 }
}

Now we started using mulsoft and it add the port to the url

Ex: www.company.com:443

This now breaks the above iRule and site are no longer found. I want to do something like contains

when HTTP_REQUEST {

 switch -glob [string tolower [HTTP::host]] { contains
 "www.company.com"      { pool company.com_www }
 "www2.company.com"     { pool company.com_www2 }
 "www3.company.com"     { pool company.com_www3 }
 "www4.company.com"     { pool company.com_www4 } 
 }
}

the F5 gives this error:

Exception caught in LocalLB::urn:iControl:LocalLB/Rule::modify_rule()
Exception: Common::OperationFailed
    primary_error_code   : 17236305 (0x01070151)
    secondary_error_code : 0
    error_string         : 01070151:3: Rule [/Common/TEST_MULSOFT] error: /Common/TEST_MULSOFT:4: error: [undefined procedure: www.company.com][www.company.com]
/Common/TEST_MULSOFT:5: error: [undefined procedure: www2.company.com][www2.company.com]
/Common/TEST_MULSOFT:6: error: [undefined procedure: www3.company.com][www3.company.com]
/Common/TEST_MULSOFT:7: error: [undefined procedure: www4.company.com][www4.company.com]

And when I try this:

when HTTP_REQUEST {

 switch -glob [string tolower [HTTP::host]] contains {
 "www.company.com"      { pool company.com_www }
 "www2.company.com"     { pool company.com_www2 }
 "www3.company.com"     { pool company.com_www3 }
 "www4.company.com"     { pool company.com_www4 } 
 }
}

The F5 give this as an error:

Exception caught in LocalLB::urn:iControl:LocalLB/Rule::modify_rule()
Exception: Common::OperationFailed
    primary_error_code   : 17236305 (0x01070151)
    secondary_error_code : 0
    error_string         : 01070151:3: Rule [/Common/TEST_MULSOFT] error: /Common/TEST_MULSOFT:4: error: [undefined procedure: www.company.com]["www.company.com"       { pool company.com_www }]
/Common/TEST_MULSOFT:5: error: [undefined procedure: www2.company.com]["www2.company.com"       { pool company.com_www2 }]
/Common/TEST_MULSOFT:6: error: [undefined procedure: www3.company.com]["www3.company.com"       { pool company.com_www3 }]
/Common/TEST_MULSOFT:7: error: [undefined procedure: www4.company.com]["www4.company.com"       { pool company.com_www4 } ]

How can I strip off the :443 from the URL so that the iRules work?

I thank you in advance for your time and help.

3 Replies

  • When you are using [HTTP::host] as the syntax, it captures Host header which also includes domain & service. You may want to like this,

    when HTTP_REQUEST { 
         Check if the host contains a colon 
        if {[HTTP::host] contains ":"}{ 
    
            Replace the Host header with the first field, split on the : 
           HTTP::header replace Host [getfield [HTTP::host] ":" 1]
    
  • Try using:

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::host]] {
     "www.company.com*"      { pool company.com_www }
     "www2.company.com*"     { pool company.com_www2 }
     "www3.company.com*"     { pool company.com_www3 }
     "www4.company.com*"     { pool company.com_www4 } 
     }
    }
    
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    What about simply using a wildcard as you're using glob?

    when HTTP_REQUEST {
    
      switch -glob [string tolower [HTTP::host]] {
     "www.company.com*"      { pool company.com_www }
     "www2.company.com*"     { pool company.com_www2 }
     "www3.company.com*"     { pool company.com_www3 }
     "www4.company.com*"     { pool company.com_www4 } 
     }
    }
    

    Does this work for you?

    N