Need some quick help on what I believe to be a simple irule. I’m looking to create an irule that does a simple redirect if the requested site has no uri.
For example:
~~request - https://example.domain.com~~
~~redirect - https://example.domain.com/example1~~
I would also like to exclude/ignore one sepicific uri.
request - https://example.domain.com/example2 - if URI = example2 then leave it alone.
Thanks!
So what you’re looking for is something like:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri] {
"" -
"/" {
HTTP::redirect "https://example.domain.com/example1"
}
}
You could, of course, write this many different ways. You don’t need to specifically call out example2 in the URI because the code is only matching empty URIs. /example2 won’t be affected.
Colin
Here is what ended up working for me after identifying all the URIs I needed. Looks messy but it works.
when HTTP_REQUEST {
if {[HTTP::uri] contains “/Microsoft-Server-ActiveSync” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/owa” } {
HTTP::uri “[HTTP::uri]”
}else {
if {[HTTP::uri] contains “/ecp” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/Autodiscover” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/EWS” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/Exchange” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/Exchweb” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/OAB” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/Public” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/rpc” } {
HTTP::uri “[HTTP::uri]”
} else {
if {[HTTP::uri] contains “/RpcWithCert” } {
HTTP::uri “[HTTP::uri]”
} else {
HTTP::uri “/owa”
}
}
}
}
}
}
}
}
}
}
}
}
nitass
April 22, 2011, 5:04am
4
hoolio
April 22, 2011, 6:17pm
5
I think you can clean that up with a switch statement:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"/microsoft-server-activesync*" -
"/owa*" -
"/ecp*" -
"/autodiscover*" -
"/ews*" -
"/exchange*" -
"/exchweb*" -
"/oab*" -
"/public*" -
"/rpc*" { do nothing for these paths}
"/rpcwithcert*" {
Rewrite the URI to /owa
HTTP::uri "/owa"
}
}
}
Also, you don’t need to set HTTP::uri to [HTTP::uri] in your example. You could just leave the clause empty to do nothing.
Aaron