Forum Discussion
Irule query to redirect a uri on a new website
Hi All
I am looking at an irule to redirect a particular URI to a new site, if certain conditions are meet, i.e a user has a particular cookie set and except if the url contains particular language (defined in the uri i.e lang=fr).
I have most of the irule working but need some pointers as I am running into an issue as the redirect to the new site is working but their are absolute paths on the new pages which I am struggling to capture in the same rule.
Below is the starting point irule so any pointers or suggestions welcome, I suspect its due to using an if as this is only triggering for /new-path/ and the other uris are then ignored:
when HTTP_REQUEST { if { [HTTP::cookie exists "NEWWEBSITE" ] && [HTTP::cookie value "NEWWEBSITE"] equals "1" && [string tolower [HTTP::uri]] starts_with "/new-path/" } { log local0. "cookie exists NEWWEBSITE and /new-path" if {[string tolower [HTTP::uri]] contains "lang=fr" || [string tolower [HTTP::uri]] contains "lang=it" }{ log local0. "contains lang [HTTP::uri], pass to ORIGNAL-WEBSITE" pool ORIGNAL-WEBSITE } else { if {[string tolower [HTTP::uri]] starts_with "/new-path/" || [string tolower [HTTP::uri]] contains "/assets/scripts/" || [string tolower [HTTP::uri]] contains "/assets/styles/" || [string tolower [HTTP::uri]] contains "/assets/fonts/" || [string tolower [HTTP::uri]] contains "/media/" }{ log local0. "contains path [HTTP::uri], pass to NEW-WEBSITE pool" pool NEW-WEBSITE log local0. "Pass to NEW-WEBSITE [HTTP::uri]" } else { pool ORIGNAL-WEBSITE log local0. "pass to ORIGNAL-WEBSITE [HTTP::host][HTTP::uri]" } } } }
Thanks in advance
2 Replies
- Stanislas_Piro2
Cumulonimbus
Hi,
Your irule had bad structure... you created two filters with the same URI...
can you try this irule:
when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] store lang parameter, blank is not present set lang [URI::query $uri lang] if { [HTTP::cookie exists "NEWWEBSITE" ] && [HTTP::cookie value "NEWWEBSITE"] equals "1" } { switch -glob $uri { "/new-path/*" { log local0. "cookie exists NEWWEBSITE and /new-path" if { $lang equals "fr" || $lang equals "it" }{ log local0. "contains lang [HTTP::uri], pass to ORIGNAL-WEBSITE" pool ORIGNAL-WEBSITE } } "*/assets/scripts/*" - "*/assets/styles/*" - "*/assets/fonts/*" - "*/media/*" { log local0. "contains path [HTTP::uri], pass to NEW-WEBSITE pool" pool NEW-WEBSITE log local0. "Pass to NEW-WEBSITE [HTTP::uri]" } default { pool ORIGNAL-WEBSITE log local0. "pass to ORIGNAL-WEBSITE [HTTP::host][HTTP::uri]" } } } } - Annsar_Akhtar
Nimbostratus
Thanks for your reply, I realised were I had been going wrong after I posted the question but thanks for pointing out the mistake in my structure, I have re written the irule based on your feedback.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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