Forum Discussion
iRule redirect based on uri or user-agent match logic.
Hello, looking for some direction here. I am trying create a rule which will match a specific set of uri and redirect if true to a prefered site and quit processing the irule. If the uri doesn't match, it will continue to the next match test for mobile in the header user-agent. If a match is found the redirect is to an other site.
Problem is, I can match the uri, but if it doesn't match the uri it doesn't seem to continue nor match when the user-agent is mobile.
Can someone tell me what I'm doing wrong here. I hope the formatting looks correct. Thanks.... ///pvr
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] {
"/about_news" -
"/*.pdf" {
HTTP::redirect "https://www.mysite.com[HTTP::uri]" }
}
switch -glob [string tolower [HTTP::header User-Agent]] {
"*mobile*" {
HTTP::redirect "https://www.myothersite.com[HTTP::uri]"
}
}
}
- BinaryCanary_19Historic F5 Account
To the naked eye, i don't see anything wrong with your logic.
You might want to add logging statements to track the values you're matching for, and log every block execution reaches to make sure there is not something unexpected happening.
- pvrobinsontx2_2NimbostratusThanks... That was my thinking that the logic was right. I've placed log local2. statements , the values are there but when it comes to the mobile section there is simply no execution as best I can tell. It's almost like there is a bug somewhere in running multiple switch statements in the same iRule. If the 1st uri match doesn't catch, I get an instant connection reset.
- BinaryCanary_19Historic F5 AccountStanislas's example above does not use multiple switch statements. give that a go.
- Stanislas_Piro2Cumulonimbus
Hi,
the irule may work when :
- URI doesn't match and user agent doesn't match
- URI match and user agent doesn't match
- URI doesn't match and user agent match
But the irule may cause a tcl error when both URI and user agent match
add a
command after eachreturn
to leave irule.HTTP::redirect
use
instead ofHTTP::path
in switch...HTTP::uri
may contain query string which can be dynamic.HTTP::uri
when HTTP_REQUEST { switch -glob [string tolower [HTTP::path]] { "/about_news" - "*.pdf" { HTTP::redirect "https://www.mysite.com[HTTP::uri]" return } default { if {[string tolower [HTTP::header User-Agent]] contains "mobile"} { HTTP::redirect "https://www.myothersite.com[HTTP::uri]" return } } } }
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