Forum Discussion

Angel_Martinez_'s avatar
Angel_Martinez_
Icon for Nimbostratus rankNimbostratus
Aug 04, 2011

iRule vs HttpClass

Hi

 

 

Nowadays my customers ask me for many redirection, for example from http to https, from domain.com to www.domain.com... usually easy things...

 

 

 

User wants to force the Host header.

 

 

- Via iRule:

 

 

rule iRule_Redirect_www.domain.com {

 

when HTTP_REQUEST {

 

if { [HTTP::host] ne "www.domain.com" } {

 

HTTP::redirect "http://www.domain.com"

 

}

 

}

 

 

- Via Httpclass

 

 

May I do something like that ¿?

 

 

profile httpclass httpclass_www.domain.com {

 

defaults from httpclass

 

pool none

 

redirect "http://www.domain.com"

 

hosts regex "![^www.domain.com*]" --> I don't know how to do a Negative RegExp

 

}

 

 

 

But what is more effective ¿? which one is less painful for the CPU ¿?

 

 

Thank you

 

3 Replies

  • It's always faster to execute logic like this natively in the product. But, in this case, "faster" can just mean you are shaving a couple dozen milliseconds off the request which is negligible. The bigger question you should ask yourself for situations like this is "what is more manageable". If it won't change very often and you just want to set it and forget it, then use the Class profile. But, if you want to have more control and options for expanding it (ie. adding elses and else-ifs), then an iRule might work out best for you.

     

     

    Cheers!

     

     

    -Joe

     

  • You'd need to use a lookbehind to do a negative match with a regex. But you could instead create an HTTP class with a string pattern matching www.domain.com with no action and then create a match all HTTP class which redirects to http://www.domain.com. The string patterns would be more efficient than a regex anyhow.

     

     

    Aaron
  • Hi Guys

     

     

    Thank you very much for your answers... very interesting points of views... I'll keep in mind both ideas..

     

     

    FYI, this is the final result:

     

     

    virtual vs_www.domain.com_80 {

     

    snat automap

     

    pool pool_www.domain.com_17800

     

    destination 10.2.56.171:http

     

    ip protocol tcp

     

    httpclass

     

    httpclass_www.domain.com

     

    httpclass_to_www.domain.com

     

    profiles

     

    pro_www.domain.com_80

     

    tcp

     

    persist per_cookie_www.domain.com

     

    }

     

    profile httpclass httpclass_www.domain.com {

     

    defaults from httpclass

     

    hosts "www.domain.com"

     

    }

     

     

    profile httpclass httpclass_to_www.domain.com {

     

    defaults from httpclass

     

    pool none

     

    redirect "http://www.domain.com"

     

    }