Forum Discussion
Scott_82504
Nimbostratus
Nov 15, 2008IRules Logic and wild care at the end
I am trying to figure out a set of IRULES. They are working for the most part. Here is my issue. If the rules do not match my any of my uri (kinda like a wildcard) I want to redirect the connection to another site. Example I type in lms2.tyco-training.com into the address bar and I want to redirect it to http://lms.tyco-training.com/knav/nav?BU=10003010. If I put anything else after example : lms2.tyco-training.com/abc (does not match uri in my rules below I want it to go to this same page http://lms.tyco-training.com/knav/nav?BU=10003010. How do I add this wild card rule ?
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/dsc"} {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002958"
} elseif { [string tolower [HTTP::uri]] starts_with "/kantech" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002735"
} elseif { [string tolower [HTTP::uri]] starts_with "/acvs_catalog" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?cmd=catalog&BU=15004409"
} elseif { [string tolower [HTTP::uri]] starts_with "/acvs" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004408"
} elseif { [string tolower [HTTP::uri]] starts_with "/mac" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005009"
} elseif { [string tolower [HTTP::uri]] starts_with "/tycosafetyproducts-fire-europe" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005089"
} elseif { [string tolower [HTTP::uri]] starts_with "/scansource" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004826"
} elseif { [string tolower [HTTP::uri]] starts_with "/SimplexMear" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004867"
} elseif { [string tolower [HTTP::uri]] starts_with "/te" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004768"
} elseif { [string tolower [HTTP::uri]] starts_with "/physicalsecurity" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004506"
} elseif { [string tolower [HTTP::uri]] starts_with "/swh" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002734"
} elseif { [string tolower [HTTP::uri]] starts_with "/tfbp" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004445"
} elseif { [string tolower [HTTP::uri]] starts_with "/scott" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002988"
} elseif { [string tolower [HTTP::uri]] starts_with "/bentel" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"
} elseif { [string tolower [HTTP::uri]] starts_with "/surgard" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"
} elseif { [string tolower [HTTP::uri]] starts_with "/amerdyn" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002733"
} elseif { [string tolower [HTTP::uri]] starts_with "/cemsys" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002736"
} elseif { [string tolower [HTTP::uri]] starts_with "/ADTContractors" } {
HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005329"
} else {
pool TIRCAP_76.24-80
}
}
THANKS IN ADVANCE
- hwidjaja_37598
Altostratus
Can you try this:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/dsc*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002958" } "/kantech*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002735" } "/acvs_catalog*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?cmd=catalog&BU=15004409"} "/acvs*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004408"} "/mac*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005009"} "/tycosafetyproducts-fire-europe*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005089"} "/scansource*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004826"} "/simplexmear*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004867"} "/te*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004768"} "/physicalsecurity*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004506"} "/swh*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002734"} "/tfbp*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004445"} "/scott*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002988"} "/bentel*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/surgard*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/amerdyn*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002733"} "/cemsys*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002736"} "/adtcontractors*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005329"} default { if {not ([string tolower [HTTP::uri]] starts_with "/knav/nav")} { HTTP::redirect "http://lms.tyco-training.com/knav/nav?BU=10003010" } } } }
- hwidjaja_37598
Altostratus
Hmm ... This one might be more efficient:when HTTP_REQUEST { if {not ([string tolower [HTTP::uri]] starts_with "/knav/nav")} { switch -glob [string tolower [HTTP::uri]] { "/dsc*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002958" } "/kantech*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002735" } "/acvs_catalog*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?cmd=catalog&BU=15004409"} "/acvs*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004408"} "/mac*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005009"} "/tycosafetyproducts-fire-europe*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005089"} "/scansource*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004826"} "/simplexmear*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004867"} "/te*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004768"} "/physicalsecurity*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004506"} "/swh*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002734"} "/tfbp*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004445"} "/scott*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002988"} "/bentel*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/surgard*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/amerdyn*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002733"} "/cemsys*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002736"} "/adtcontractors*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005329"} default { HTTP::redirect "http://lms.tyco-training.com/knav/nav?BU=10003010" } } } }
- Scott_82504
Nimbostratus
This is working great, ran into one more issue and I trying to figure out the logic.. - hwidjaja_37598
Altostratus
What about this:when HTTP_REQUEST { if { not ( \ ([string tolower {[HTTP::uri]}] starts_with "/knav/nav") or \ ([string tolower "http://[HTTP::host][HTTP::path]"] eq \ "http://lmsadmin2.tyco-training.com/assembler/dev") \ ) } { switch -glob [string tolower [HTTP::uri]] { "/dsc*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002958" } "/kantech*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002735" } "/acvs_catalog*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?cmd=catalog&BU=15004409"} "/acvs*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004408"} "/mac*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005009"} "/tycosafetyproducts-fire-europe*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005089"} "/scansource*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004826"} "/simplexmear*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004867"} "/te*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004768"} "/physicalsecurity*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004506"} "/swh*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002734"} "/tfbp*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004445"} "/scott*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002988"} "/bentel*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/surgard*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/amerdyn*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002733"} "/cemsys*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002736"} "/adtcontractors*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005329"} default { HTTP::redirect "http://lms.tyco-training.com/knav/nav?BU=10003010" } } } }
- hwidjaja_37598
Altostratus
If it didn't work, try to use starts_with instead of eq in:if { not ( \ ([string tolower {[HTTP::uri]}] starts_with "/knav/nav") or \ ([string tolower "http://[HTTP::host][HTTP::path]"] starts_with \ "http://lmsadmin2.tyco-training.com/assembler/dev") \ ) } {
- Scott_82504
Nimbostratus
Need some more help. As they did more testing we realized none of the graphic coming up on the the redirect pages. The redirect was trying to grab a image but getting redirect by catch all at the end. I am in same position as the first post. - Scott_82504
Nimbostratus
Here is the image gettng redirected via HTTP WATCH - hwidjaja_37598
Altostratus
what about this:when RULE_INIT { set ::ForwardList [list / .html .htm .asp .pl ] } when HTTP_REQUEST { if { ( not ( \ ([string tolower {[HTTP::uri]}] starts_with "/knav/nav") or \ ([string tolower "http://[HTTP::host][HTTP::path]"] eq \ "http://lmsadmin2.tyco-training.com/assembler/dev") \ )) and ([matchclass [HTTP::path] ends_with $::ForwardList]) \ } { switch -glob [string tolower [HTTP::uri]] { "/dsc*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002958" } "/kantech*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002735" } "/acvs_catalog*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?cmd=catalog&BU=15004409"} "/acvs*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004408"} "/mac*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005009"} "/tycosafetyproducts-fire-europe*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005089"} "/scansource*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004826"} "/simplexmear*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004867"} "/te*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004768"} "/physicalsecurity*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004506"} "/swh*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002734"} "/tfbp*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15004445"} "/scott*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002988"} "/bentel*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/surgard*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002959"} "/amerdyn*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002733"} "/cemsys*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15002736"} "/adtcontractors*" { HTTP::redirect "http://lms2.tyco-training.com/knav/nav?BU=15005329"} default { HTTP::redirect "http://lms.tyco-training.com/knav/nav?BU=10003010" } } } }
- Scott_82504
Nimbostratus
Do you know why I would come up with this error for the above Irule - hwidjaja_37598
Altostratus
Make sure there is no space after "\"
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