http to https redirect irule with an exception
I'm tasked with changing a http redirect irule to add an exception, if the url includes a certain word "investor-relations", then do not redierct to https, for everything else, redirect to https.
the current irule for just the http to https redirect is:
when HTTP_REQUEST {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}
I tried changing it to below (meaning if it doesn't equal that url, then redirect to https)
when HTTP_REQUEST {
if { ![HTTP::uri] equals "/about-*****/investor-relations" } {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}
}
but it does not work.
As I could not keep trying different thing on production, I received a test vip and environment to apply a similar iRule and test with curl command but so far nothing works.
I tried changing the iRule and add "else" but that breaks the vip.
when HTTP_REQUEST {
if { ![HTTP::uri] ends_with "postinfo.html" } {
HTTP::respond 301 Location "http://[getfield [HTTP::host] ":" 1][HTTP::uri]"
} else {
HTTP::respond 301 Location "https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}
}
Can you please help me with what I might be missing?
The "!" (not) operation needs to negate the statement "uri equals something". Put the statement in parentheses with the "!" outside as follows: { !([HTTP::uri] equals "/about-*****/investor-relations") }
Also, try contains "investor-relations"
OR
matches_glob "/about-*/investor-relations"
"equals" expects the literal "*" character