Forum Discussion
Nicolas_Bellen1
Jun 03, 2011Nimbostratus
REGEX Alternatives
I've been trying to figure out how i'd structure a particular portion of my iRule to look for values contained in a string, instead of a regular expression but i'm having some difficulty:
The first conditional is straightforward and has a static value. However the second conditional would be DRC followed by 5 numbers. Is there any way to structure this so it uses a more efficient method? Here's what i have:
if {([string tolower [HTTP::uri]] contains "mastermenu") ||
([HTTP::uri] matches_regex {DRC(\d)+})}
The other issue i'm running into is how i would replace the host portion of the redirect location, yet leave the URI intact. I tried the following, but couldn't quite figure out how to structure the first parameter of the string map to match on the host portion without using a regular expression. I borrowed this portion (from http://devcentral.f5.com/wiki/default.aspx/iRules/RewriteHTTPRedirectHostname.html), but couldn't quite piece it together.
if { [HTTP::is_redirect] } {
HTTP::header replace Location [string map -nocase {"abc.example.com" "def.example.com"} [HTTP::header value Location]]}
Any help would be appreciated!
Nick
- hooleylistCirrostratusHi Nick,
- Nicolas_Bellen1NimbostratusAaron,
- hooleylistCirrostratusThe values for most HTTP:: commands are cached within the same event and priority. If you don't specify an event priority a default of 500 is used. You can use a later priority event (like 501) to view the change from the iRule. Also, the curly braces in string map will prevent command and variable substitution. You can use double quotes instead:
... if { [HTTP::is_redirect] } { log local0. "Original Location: [HTTP::header value Location]" HTTP::header replace Location [string map -nocase "[URI::host [HTTP::header value Location]] def.example.com" [HTTP::header value Location]] } } when HTTP_RESPONSE priority 501 { log local0. "Updated Location: [HTTP::header value Location]" }
- Nicolas_Bellen1NimbostratusAaron,
- hooleylistCirrostratusHi Nick,
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