Forum Discussion

muzammil_88686's avatar
muzammil_88686
Icon for Nimbostratus rankNimbostratus
Feb 13, 2013

Blocking 2 URLs and Allowing 1 URL

Dear Team,

 

 

I want to block the below URLs

 

www.xyz.com/cc_page

 

www.xyz.com

 

 

And want to allow the below URL

 

www.xyz.com/test_page

 

 

Could someone help me with the iRule?

 

5 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    muzammil,

    Loads of examples of this type of irule on DC.

    How about something like this:

    when HTTP_REQUEST {
       switch [string tolower [HTTP::uri]] {
       "/cc_page" -
       "/" { drop }
       }
    } 

    This would inherently allow test_page uri.

    Or you may want to redirect to test_page thus:

    when HTTP_REQUEST {
       switch [string tolower [HTTP::uri]] {
       "/cc_page" -
       "/" { HTTP::redirect "http://[HTTP::host]/test_page" }
       }
    } 

    This probably depends on what other URIs you have and what you want to do with them. Hope this is a good starting point though.

    Hope this helps,

    N
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    muzammil,

     

     

    That post didn't quite come out as expected. Here are my two options:

     

     

    when HTTP_REQUEST {

     

    switch [string tolower [HTTP::uri]] {

     

    "/cc_page" -

     

    "/" { drop }

     

    }

     

    }

     

     

    This would inherently allow test_page.

     

     

    Or something friendlier perhaps:

     

     

    when HTTP_REQUEST {

     

    switch [string tolower [HTTP::uri]] {

     

    "/cc_page" -

     

    "/" { HTTP::redirect "http://[HTTP::host]/test_page" }

     

    }

     

    }

     

     

    N
  • Dear Nathan,

     

     

    Below iRule which was suggested by you works well.

     

     

    when HTTP_REQUEST {

     

    switch [string tolower [HTTP::uri]] {

     

    "/cc_page" -

     

    "/" { drop }

     

    }

     

    }

     

     

    Is there any way to allow only "/test_page" and block all "/*" ?
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    How about something with there following:

     

     

    if { [HTTP::uri] ne "/test_page" } {

     

    drop

     

    }
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    You could always use a data group too and do a class match on the contents of this in an irule. This would be useful if you wanted to add further allowed URIs.

    when HTTP_REQUEST {
      if { [class match [HTTP::uri] ne "allowed_uris"] } {
        drop
      }
    } 

    I think in small numbers performance of class match vs switch/if isn't much of a concern but it's another option nonetheless.

    Hope this helps,

    N