Forum Discussion
How best to accomplish HTTP redirection for specific URLs?
Okay, this is a little hacky, but there is technically a way to achieve "regex-like" behavior with data groups. I'll start with the data group.
/slow1234/nossl/is/
/fast1234/nossl/is/
...
The digits in the URI aren't important and I'm purposely limiting the URIs to three-levels deep, but yours should be limited to the lowest common denominator for your matched URIs. Now the iRule:
when HTTP_REQUEST {
limit the request URI to three levels
Example: /slow1234/nossl/is/slow/ becomes /slow1234/nossl/is/
set uri [string range [HTTP::uri] 0 [string first "/" [HTTP::uri] [expr [string first "/" [HTTP::uri] [expr [string first "/" [HTTP::uri] 1] +1]]+1]]]
Turn the URI into a glob pattern based on numeric values
Example: /slow1234/nossl/is/slow becomes /slow*/nossl/is/slow
regsub -all -nocase {\d+} $uri "*" globuri
append globuri "*"
Search for the glob pattern in the data group
if { not ( [lindex [class get -nocase glob_datagrouop $globuri] 1] eq "" ) } {
log local0. "no match"
perform redirects
}
}
The idea here is that I'm using the [class get ] command with a glob pattern - not truly a regex itself, but the regsub command above makes sure that only digits are affected. So to illustrate what's happening:
-
The URI is first truncated to three levels. That'll make more sense in a moment.
-
The regsub command replaces any instance of a sequential digits in the URI with a glob "*" character, and then an additional "*" is appended to the end.
-
This pattern is fed into the [class get ] command, which produces a list. If the pattern matches a single data group entry, then it's flagged as a match. Otherwise all or multiple records are returned and it's not a match. Of course you want to make sure that your URI patterns cannot produce multiple results in the search.
The reason for limiting the data group URI is that you can't really do a "starts_with" expression like you can with other class commands. So, for example, if the data group URI was something like "/slow1234/nossl/is/" and the request URI was "/slow3454/nossl/is/slow/test/foo/bar", the glob pattern would become "/slow*/nossl/is/slow/test/foo/bar" - and this wouldn't match the data group.
Recent Discussions
Related Content
* 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