Forum Discussion

Austin_Geraci's avatar
Aug 17, 2010

matchclass, code okay, and would you do this differently?

Okay so I'm looking to redirect requests to mydomain.com and http://www.mydomain.com/ to https://www.mydomain.com/secure, if no matches load balance to the pool specified in the VS.

 

 

Is this code okay and or would you guys/gals do this any differently?

 

 


 when HTTP_REQUEST {
     set host [matchclass [string tolower [HTTP::host]] $::myclass " "]
 Check if there was a match
if {$host ne ""}{   
     HTTP::respond 301 Location "https://www.mydomain.com/secure"
} else {
       pool "mysecurepool_443"
  }
    }

12 Replies

  • Posted By iRuleYou on 08/17/2010 11:01 AM

    hmm not with all browsers... need the stringtolower to work..

    heh needed to look a litle closer... supposed to be string tolower not one word I believe

    Good point!
     when HTTP_REQUEST {
         if { [matchclass [string tolower [HTTP::host]] eq $::myclass] } {
              HTTP::respond 301 Location "https://www.mydomain/secure" 
    } else { pool "mysecurepooll_443" }      
        }
    
    That compiles.
  • To make the iRule CMP compatible for 9.4.4+ you can remove the $:: prefix on the datagroup name:

    
    when HTTP_REQUEST {
       if { [matchclass [string tolower [HTTP::host]] eq myclass] } {
          HTTP::respond 301 Location "https://www.mydomain/secure"
       } else {
          pool "mysecurepool_443"
       }
    }
    

    Aaron