Forum Discussion

Michiel_61345's avatar
Michiel_61345
Icon for Nimbostratus rankNimbostratus
Apr 18, 2012

class match hostname in 10.2.1 irule

Guys,

 

 

My website www.mycomp.com also has some country specific domain registration addresses. Customers visiting my website on a regional address need to be routed to my .com address and get my website shown.

 

 

IMHO, most decent way to do this is to use a data group for this, put in the country specific domain names and match the domain name request against the data group entries and do a redirect.

 

 

Implementation:

 

 

I've created a string type data group named "website_aliases"

 

Filled it with string/values equal to domainname/pool (pool is not used as an reference but each string needs a value), a couple of examples:

 

www.mycomp.de pool_mycomp

 

www.mycomp.fr pool_mycomp

 

www.mycomp.nl pool_mycomp

 

 

The in the irule:

 

 

when HTTP_REQUEST {

 

set host [string tolower [HTTP::host]]

 

set uri [string tolower [HTTP::uri]]

 

 

switch -exact $host {

 

"www.mycomp.com" {

 

pool pool_mycomp

 

}

 

if {[class match $host equals website_aliases]} {

 

HTTP::redirect http://www.mycomp.com/ }

 

}

 

}

 

 

Irule is accepted so contains no syntax errors.

 

Still after synch, when trying in a browser http://www.mycomp.com , it is reinitialised

 

Any of the aliases also don't work either so https://www.mycomp.de is not redirected to http://www.mycomp.com

 

 

Any ideas?

3 Replies

  • e.g.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool pool_mycomp
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b class website_aliases list
    class website_aliases {
       {
          "www.mycomp.de"
          "www.mycomp.fr"
          "www.mycomp.nl"
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if { [class match -- [HTTP::host] equals website_aliases] } {
          HTTP::redirect "http://www.mycomp.com"
       }
    }
    }
    
    [root@ve1023:Active] config  curl -I http://www.mycomp.com
    HTTP/1.1 200 OK
    Date: Wed, 18 Apr 2012 13:21:10 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT
    ETag: "4183e4-3e-9c564780"
    Accept-Ranges: bytes
    Content-Length: 62
    Content-Type: text/html; charset=UTF-8
    
    [root@ve1023:Active] config  curl -I http://www.mycomp.de
    HTTP/1.0 302 Found
    Location: http://www.mycomp.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Hmm, in you're rule you specify an "--" in the class match, why is that?:

     

    if { [class match -- [HTTP::host] equals website_aliases] }

     

     

    Furthermore interesting that you're setup works...

     

     

    Thnx,

     

    Michiel

     

  • -- Terminates option processing (useful if the or begins with a hyphen).class wiki

     

    https://devcentral.f5.com/wiki/iRules.class.ashx

     

     

     

    your irule is not working since you are not able to mix switch with if-clause likes that.

     

     

    hope this helps.