iRule to remove uri if it starts with a specific path
I'm trying to write an iRule (v11.6) that simply removes the entire uri if someone tries to enter a forbidden path. If host is https://foo.com and they try to add https://foo.com/console or any path that begins with /console/, we want it to strip the uri completeley and just request https://foo.com
This is what I currently have. Is there a better way to strip uri than a redirect, or does this look acceptable? Suggestions are welcome and appreciated.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/console" } {
HTTP::redirect https://[HTTP::host]
}
}
A redirect is good here if you don't want to issue a 403. If you are going to use a redirect I would suggest a 301 to minimize on repeat traffic from users. 301 is a permanent redirect and the browser will do an internal redirect next time the browser visits vs 302 the browser will always hit your VIP to get the redirect.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/console" } { HTTP::respond 301 noserver Location "https://[HTTP::host]" } }