Forum Discussion
Data Groups for HTTP redirects -- can't find element in DG with class match
I am trying to get an iRule to look at a data group and if it finds a match, redirect to the value in the element, otherwise do a standard redirect including the URI. Here's the iRule I built and a sample of the elements in my data group.
When I run traffic through the iRule it shows that srcLocBoolean = 0 and $destLoc is NULL
What am I missing?
===== iRule ===== when HTTP_REQUEST { log local0. "Entering iRule" set incomingURI [string tolower [HTTP::uri]] log local0. "iRule incoming URI = $incomingURI" set destLoc [class match -value -- $incomingURI contains DG_Redirects] set srcLocBoolean [class match $incomingURI contains DG_Redirects] log local0. "iRule class Match Boolean = $srcLocBoolean" log local0. "iRule Destination Location = $destLoc" if { $srcLocBoolean eq "1" } then { log local0. "iRule Redirecting [HTTP::host][HTTP::uri] to $destLoc" HTTP::redirect $destLoc
} else { HTTP::redirect [HTTP::uri] } }
===== Data Group element ===== "; := ";, "; := ";,
- Samir_Jha_52506
Noctilucent
In varibale you mentioned to match URI but in class its full URL.
Try below iRule...
class myRedirects_dg { "/how-it-works https://new.domain/new-base-dir/pages/about" "/contact https://new.domain/new-base-dir/pages/help" } when HTTP_REQUEST { set destLoc [findclass [string tolower [HTTP::uri]] myRedirects_dg] if { $destLoc ne "" }{ HTTP::redirect [getfield $destLoc " " 2][HTTP::uri] Connection Close unset destLoc } else { HTTP::redirect https://new.domain/new-base-dir[HTTP::uri] } }
- jdanowit
Nimbostratus
Still no luck. I was using URI and the contains option to be more greedy about the search. I can use the elements exactly from the Data Group if that's easier.
===== Data Group item ===== "; := ";,
==== iRule ===== when HTTP_REQUEST { log local0. "Entering iRule" set incomingURI [string tolower [HTTP::uri]] log local0. "iRule incoming URI = $incomingURI" set destLoc [findclass [string tolower [HTTP::uri]] DG_Redirects log local0. "iRule class Match Boolean = $srcLocBoolean" log local0. "iRule Destination Location = $destLoc" if { $destLoc ne "" } { log local0. "iRule Redirecting [HTTP::host][HTTP::uri] to [getfield $destLoc " " 2]" HTTP::redirect [getfield $destLoc " " 2] } else { HTTP::redirect [HTTP::uri] log local0. "iRule Redirecting [HTTP::host][HTTP::uri] to [HTTP::uri]" } }
===== Output ====== Nov 6 09:55:16 FDC-F501-OUTSIDE info tmm[20859]: Rule /Common/stepsforwardRedirectSilverChair : Entering stepstest iRule Nov 6 09:55:16 FDC-F501-OUTSIDE info tmm[20859]: Rule /Common/stepsforwardRedirectSilverChair : stepstest iRule incoming URI = /about-steps-forward Nov 6 09:55:16 FDC-F501-OUTSIDE info tmm[20859]: Rule /Common/stepsforwardRedirectSilverChair : stepstest iRule class Match Boolean = 0 Nov 6 09:55:16 FDC-F501-OUTSIDE info tmm[20859]: Rule /Common/stepsforwardRedirectSilverChair : stepstest iRule Destination Location = Nov 6 09:55:16 FDC-F501-OUTSIDE info tmm[20859]: Rule /Common/stepsforwardRedirectSilverChair : stepstest iRule Redirecting stepstest.ama-assn.org/about-steps-forward to https://amaecrc.silverchair.com/steps-forward/about-steps-forward
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