Forum Discussion
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"
}
}
- Chris_Miller
Altostratus
Are you using 10.x? - 9.4.8, but you can reference what you would do differenlty in 10x as well..
- Chris_Miller
Altostratus
when HTTP_REQUEST { if { [class match [stringtolower [HTTP::host]] eq myclass] } { HTTP::respond 301 Location "https://www.mydomain/secure" } else { pool "mysecurepooll_443" } }
- but code looks fine for 9.4.8, correct?
- Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:10 AM
I think that's the only change necessary to make it work for 9.x...see if it compiles. You shouldn't have to set the host variable or see whether it exists...checking whether it matches your datagroup should accomplish that.when HTTP_REQUEST { if { [matchclass [stringtolower [HTTP::host]] eq $::myclass] } { HTTP::respond 301 Location "https://www.mydomain/secure" } else { pool "mysecurepooll_443" } }
- hmmm when I was first figuring out findclass hoolio had an example with using set, and I've been using it ever since... do you need it for findclass and not matchclass?
- Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:45 AM - I get the following error trying to compile your code..
- Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:49 AM - hmm not with all browsers... need the stringtolower to work..
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