Forum Discussion

MatthewStyles_3's avatar
MatthewStyles_3
Icon for Nimbostratus rankNimbostratus
Jun 26, 2018

iRule to redirect URL based on source address

Hi there,

 

I am looking to see if it is possible to have an iRule build in the following functionality to a website:

 

Allow internet access to https://mywebsite.co.uk for all internet traffic However when access is attempted to https://mywebsite.co.uk/admin or https://mywebsite.co.uk/admin2 customers are redirected back to the main URL again, unless they are from internal business staff (always coming from the same source IP E.g 10.0.0.1) where they are allowed through to the /admin /admin2 pages.

 

Is this possible?

 

Many thanks for any and all help!

 

Matt

 

3 Replies

  • You could use a simple iRule like this

    when HTTP_REQUEST {
        if {([HTTP::uri] equals "/admin") || ([HTTP::uri] equals "/admin2")} {
            if {!([IP::client_addr] equals "10.0.0.1")} {
                HTTP::redirect https://mywebsite.co.uk
            }
        }
    }
    

    You could also use a datagroup to store your IP addresses if you plan on using more than one:

    when HTTP_REQUEST {
        if {([HTTP::uri] equals "/admin") || ([HTTP::uri] equals "/admin2")} {
            if {!([class match [IP::client_addr] equals "my_datagroup"])} {
                HTTP::redirect https://mywebsite.co.uk
            }
        }
    }
    

    You can take this a step further and add the URIs to a datagroup too:

     when HTTP_REQUEST {
        if {[class match [HTTP::uri] equals "my_uri_datagroup"]} {
            if {!([class match [IP::client_addr] equals "my_ip_datagroup"])} {
                HTTP::redirect https://mywebsite.co.uk
            }
        }
    }
    
  • You need a data-group existing that contains a list of allowed IPs or subnets for this iRule to work.

    when HTTP_REQUEST {
      if { [string tolower [HTTP::path]] starts_with "/admin" and !([class match [IP::client_addr] equals data-group_of_IPs_and/or_subnets ]) } {
        HTTP::redirect "https://[HTTP::host]/"
        }
    }