Forum Discussion

mfkk531_168091's avatar
mfkk531_168091
Icon for Nimbostratus rankNimbostratus
Apr 28, 2015
Solved

iRule for 403 redirect?

Hi All, I need help in refining this irule.

when HTTP_REQUEST {
    if { ([HTTP::uri] contains "/recommended") or 
          ([HTTP::uri] contains "/activate") or 
          ([HTTP::uri] contains "/activated")or 
          ([HTTP::uri] contains "/userStatus")or 
          ([HTTP::uri] contains "/recByCat")or 
          ([HTTP::uri] contains "/targeted") } {
        HTTP::respond 403 content {403 Unauthorized}
    }
}
  • Hello M,

    The below is pretty much a template, depending on how you want the value to match within the URI. I've included the link to the switch section of the iRules wiki, a very good resource. The way I'm utilizing the wildcard would make these match URI when they begin with the value.
    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
        "/recommended*" -
        "/activate*" -
        "/activated*" - 
        "/userstatus*" - 
        "/recbycat*" - 
        "/targeted*"     { HTTP::respond 403 content {403 Unauthorized}}
        }
    }  
    

    https://devcentral.f5.com/wiki/iRules.switch.ashx

8 Replies

  • I'm trying to use switch -glob tolower for it, but cant figure out the syntaxes

     

    Thanks in advance

     

  • You can use a switch statement, but it will look a little strange since you are doing the same thing for all cases. It would look something like this:

    when HTTP_REQUEST {
        switch  [string tolower [HTTP::uri]] {
            "/recommended" { HTTP::respond 403 content {403 Unauthorized}
            "/activate"    { HTTP::respond 403 content {403 Unauthorized}
            "/activated"   { HTTP::respond 403 content {403 Unauthorized}
            "/userStatus"  { HTTP::respond 403 content {403 Unauthorized}
            "/recByCat"    { HTTP::respond 403 content {403 Unauthorized}
            "/targeted"    { HTTP::respond 403 content {403 Unauthorized}
        }
    }
    
  • Hello M,

    The below is pretty much a template, depending on how you want the value to match within the URI. I've included the link to the switch section of the iRules wiki, a very good resource. The way I'm utilizing the wildcard would make these match URI when they begin with the value.
    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
        "/recommended*" -
        "/activate*" -
        "/activated*" - 
        "/userstatus*" - 
        "/recbycat*" - 
        "/targeted*"     { HTTP::respond 403 content {403 Unauthorized}}
        }
    }  
    

    https://devcentral.f5.com/wiki/iRules.switch.ashx

    • Robert_Luechte2's avatar
      Robert_Luechte2
      Icon for Cirrus rankCirrus
      This is a better solution than mine. I was unaware of the ability to put multiple options together like this.
  • DEJ's avatar
    DEJ
    Icon for Nimbostratus rankNimbostratus

    Hello M,

    The below is pretty much a template, depending on how you want the value to match within the URI. I've included the link to the switch section of the iRules wiki, a very good resource. The way I'm utilizing the wildcard would make these match URI when they begin with the value.
    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
        "/recommended*" -
        "/activate*" -
        "/activated*" - 
        "/userstatus*" - 
        "/recbycat*" - 
        "/targeted*"     { HTTP::respond 403 content {403 Unauthorized}}
        }
    }  
    

    https://devcentral.f5.com/wiki/iRules.switch.ashx

    • This is a better solution than mine. I was unaware of the ability to put multiple options together like this.