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"
}
}12 Replies
- 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" } }
I think that should work. This is what I'd do for v10. - but code looks fine for 9.4.8, correct?
- Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:10 AM
but code looks fine for 9.4.8, correct?
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?
The code I posted compiled fine but did not work.. I'll give it a try without setting my host.. - Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:45 AM
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?
The code I posted compiled fine but did not work.. I'll give it a try without setting my host..
When doing class searches, you'd typically use "set" if you wanted to set a variable to the value that corresponds with a data group entry. If you're simply checking whether the host exists in the data group, all you need is the "if, eq" - I get the following error trying to compile your code..
line 2: [undefined procedure: stringtolower] [stringtolower [HTTP::host]] - Chris_Miller
Altostratus
Posted By iRuleYou on 08/17/2010 10:49 AM
I get the following error trying to compile your code..
line 2: [undefined procedure: stringtolower] [stringtolower [HTTP::host]]
Since host is lowered by the browser, you can probably ditch the stringtolower for now...will look at syntax in a bit. - 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
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
