Forum Discussion
Angel_Martinez_
Nimbostratus
Aug 04, 2011iRule 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 - hoolio
Cirrostratus
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 - Angel_Martinez_
Nimbostratus
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"
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects