Forum Discussion
irule syntax check
Got a check on an Irule.. the rule needs to forward http requests not containing the URI /dashboard onto the default pool someother-http-farm.
If the http request does contain /dashboard in the URI, then redirect it to https retain the hostname / URI string
This is the Irule I propose to use..
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/dashboard*" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } else
default { pool someother-http-farm } } }
5 Replies
- Stanislas_Piro2
Cumulonimbus
you want this:
- don't use wildcard in contains, starts_with, ends_with equals conditions
- wrong syntax in else --> removed default
-
I removed one closing bracket
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }
I also need a rule that can have sioe other conditions..
Can I use
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" or "/something" or "/something"} { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } else { pool someother-http-farm } }
- Stanislas_Piro2
Cumulonimbus
the best way with multiple values is switch: ( - at the end of choices is like a "or" )
when HTTP_REQUEST { switch -glob -- [string tolower [HTTP::path]] { "/dashboard*" - "/something*" - "/somethingelse*" { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } default { pool someother-http-farm } } } ok thanks that's brilliant... once the https redirect is done then we would need to drop the /URI onto a different farms from the https Virtual server: so I am thinking this ?
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/dashboard" or "/something"} { pool some-farm } if { [string tolower [HTTP::uri]] starts_with "/somethingelse" } { pool someother-farm } default {
pool default-farm }- Stanislas_Piro2
Cumulonimbus
OK,
last answer... next time, try to find yourself... there is a search icon on the top right corner... enter "irule wiki"... I swear you will find everything about irules...
when HTTP_REQUEST { switch -glob -- [string tolower [HTTP::path]] { "/dashboard*" - "/something*" { HTTP::redirect "https://[HTTP::host][HTTP::uri]" return } "/somethingelse*" { pool someother-farm } default { pool someother-http-farm } } }
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