Forum Discussion

stan_peachey_86's avatar
Nov 16, 2015
Solved

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]"
        }
    }
    

6 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Stan,

    What about:

    when HTTP_REQUEST {
      if { [string tolower [HTTP::uri]] starts_with "/console" } {
      HTTP::uri "/"
     }
    }
    

    My lab is down at the moment so can't test but should work.

    N

  • With redirect, user will get a 30x. So, you will have more requests and connections.

     

    Nathan changes URI by a new one for the same connection. Faster and less consuming.

     

  • 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]"
        }
    }
    
  • 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]"
        }
    }