Forum Discussion
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
- Lee_Sutcliffe
Nacreous
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 } } }
- Jer_O__175899
Nimbostratus
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]/" } }
- I_R_101_110
Cirrus
Though it is possible to accomplish this via an iRule it is more computationally efficient to configure an ltm traffic policy:
Configure your match statements (i.e when the uri is/contains /admin2) then use the redirect action to point things back at the main URL when the match conditions are fulfilled.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com