Forum Discussion
skarpovi_111573
Nimbostratus
Mar 25, 2008Redirect based on the source IP
Folks, can anyone help.
i need something like this:
when HTTP_REQUEST {
if { [TCP::local_port] eq "80" } """ and source IP = 10.x.x.x"""" then redirect to
{
HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1"
}
if { [TCP::local_port] eq "80" } """ and source IP = all others"""
then redirect to
{
HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2"
}else {
pool eRoom-Servers-Pool
}
}
10 Replies
- Nicolas_Menant
Employee
Hi,
Should looks like this:when HTTP_REQUEST { if {([TCP::local_port] eq "80") AND ([IP::client_addr] eq "10.x.x.x") } { HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1" } elseif {[TCP::local_port] eq "80" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2" } else { pool eRoom-Servers-Pool } } - skarpovi_111573
Nimbostratus
here is the error i'm getting
01070151:3: Rule [rule1] error:
line 4: [parse error: extra characters after close-brace] [else if {[TCP::local_port] eq "80" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link"
}else {
pool Servers-Pool
}
]
line 6: [undefined procedure: }else] [}else {
pool Servers-Pool
}] - Nicolas_Menant
Employee
This code complie on my bigip, after if you still have issue, i would recommend to use the iRule editor which will help you to troubleshoot syntaxwhen HTTP_REQUEST { if {([TCP::local_port] eq "80") and ([IP::client_addr] eq "10.2.3.4")} { HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1" } elseif {[TCP::local_port] eq "80" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2" } else { pool eRoom-Servers-Pool } } - skarpovi_111573
Nimbostratus
tried to play with brackets - fixed some errors, but still have some:
70151:3: Rule [eRoom-rule] error:
line 2: [parse error: PARSE syntax 53 {syntax error in expression " ([TCP::local_port] eq "80") AND ([IP::client_addr] equals ...": extra tokens at end of expression}] [{ ([TCP::local_port] eq "80") AND ([IP::client_addr] equals "10.0.0.0/16") }] - skarpovi_111573
Nimbostratus
i'm looking for multiple IP's as a source, not a single IP - Nicolas_Menant
Employee
if it's multiple with the same first digits then change:
if {([TCP::local_port] eq "80") and ([IP::client_addr] eq "10.2.3.4")} {
by
if {([TCP::local_port] eq "80") and ([IP::client_addr] starts_with "10.")} {
If it's completely different IP addresses then you'll need to use a class and the matchclass command - skarpovi_111573
Nimbostratus
Thanks for help. works with single IP, will try with multiple
by the way, tried to use class. matchclass but wasn't be able to make it work. not sure how and where to define class/matchclass
is it possible to use ([IP::client_addr] eq "10.0.0.0/16") - Nicolas_Menant
Employee
Glad to hear that !
Click here - Nat_Thirasuttakorn
Employee
you may try IP::addr (see examples)
http://devcentral.f5.com/Wiki/default.aspx/iRules/IP__addr.html - Nicolas_Menant
Employee
Sorry forgot the matchclass wiki page:
Click here
and yes you can use the syntax you said but this way:
[IP::addr [IP::client_addr]/16 equals 10.0.0.0]
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
