Forum Discussion
tacobell_112236
Nimbostratus
Feb 21, 2011Redirect Based on IP
Hello all- Im a newbie- can someone assist .
I need to create an Irule wheras specefic URL's can only be accessed based on IP address(s) and if not on the IP range I need to redirect to another URL .
/axampleherAdmin
/plusprods
/NAACP/admin
/ESPN/admin
/Production/registry
I know I can use datagroup names but not sure how. I found an IRule that is what I need except I dont know how to manipulate it to do what I need any guidance is appreciated.
IRule : http://devcentral.f5.com/wiki/defau...rHost.html
12 Replies
Sort By
- Chris_Miller
Altostratus
If you'd like to use data groups, I'd recommend creating a string-type group containing the URIs (in lowercase) and going from there. Also, you could consider doing a data group for the IP addresses if there's multiple ranges. From there, it'd be something like this:when HTTP_REQUEST { if { [class match [string tolower [HTTP::uri]] eq uri_datagroup] and [class match [IP::client_addr] ne address_datagroup] } { HTTP::redirect "http://www.example.com" } }
- tacobell_112236
Nimbostratus
Im sorry I dont understand what you mean? - Chris_Miller
Altostratus
I assume the rule I wrote would be exactly what you need. You can find "data groups" in the GUI by going to Local Traffic > iRules > Data Groups. When you create a new one, you can make it "string" or "address." My iRule assumes you make one "string" data group called "uri_datagroup" and one "address" data group called "address_datagroup." - tacobell_112236
Nimbostratus
yes its exact;y what i need . I understand the creation of the datagroups but can you clarify...can I use only your rule or do I need to use something else in conjunction with your rule?
- Chris_Miller
Altostratus
My iRule should be all you need. ne means not equal. That should work fine. If not, I'll change the syntax. - tacobell_112236
Nimbostratus
I get an error: - Chris_Miller
Altostratus
V9 is a bit different. Try thiswhen HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] eq uri_datagroup] and [matchclass [IP::client_addr] ne address_datagroup] } { HTTP::redirect "http://www.example.com" } }
- hoolio
Cirrostratus
One small suggestion:when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] eq uri_datagroup] and not ([matchclass [IP::client_addr] eq address_datagroup]) } { HTTP::redirect "http://www.example.com" } }
- Chris_Miller
Altostratus
Aaron - I thought about using ! but assumed it would support "ne" since it supports "eq." Any idea why it's not supported? - hoolio
Cirrostratus
Here's the wiki page entry for this:
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects