Forum Discussion

N__Tariq_149828's avatar
N__Tariq_149828
Icon for Nimbostratus rankNimbostratus
Nov 30, 2016

iRule to restrict user access to specific URL

I am pretty new to iRules and I have following requirement to restrict user access to single path i.e. https://internal.company.com.au/path/*

 

If any user tries to access a different path e.g. https://internal.company.com.au/path2/* then they should be redirected to https://internal.company.com.au/path/*

 

Is this achievable via iRules? Would anyone be able to share a sample code?

 

1 Reply

  • Hi N. Tariq,

    you may try the iRule below...

    when HTTP_REQUEST {
        if { ( [string tolower "[HTTP::host][HTTP::path]"] starts_with "internal.company.com.au/path/"  } then {
             Allow the request...      
        } else {
            Redirect the request...
            HTTP::redirect "https://internal.company.com.au/path/"
        }
    }
    

    Note: The iRule checks if the requested HTTP host and path starts_with "internal.company.com.au/path/". If this check is true, the iRule allows the ongoing request. If the HTTP host and/or path is different, then it would send a redirect to https://internal.company.com.au/path/.

    Cheers, Kai