Forum Discussion
Redirect match country and string not in url
I'm using a datagroup like below and the Irule like below. I'm trying to add a statement where if it matches the country australia and doesn't have pid=search in the url, redirect to x else redirect to y. I've tried writing the if statement like this
if
{ $redir ne "" } and { not ([HTTP::uri] contains "pid=search")}
and it barfs on me. Any help would be appreciated.
Irule
when HTTP_REQUEST {
set redir [class match -value -- [whereis [IP::client_addr]] contains country-redirect]
if { $redir ne "" } {
HTTP::redirect $redir
}
else {
HTTP::redirect "http://default.example.com/"
}
}
}`
Datagroup
ltm data-group internal country-redirect {
records {
AU {
data http://www.example1.com/
}
CR {
data http://www.example2.com/
}
MX {
data http://www.example2.com/
}
UK {
data http://www.example1.com/
}
US {
data http://www.example1.com/
}
}
type string
}
2 Replies
- Faruk_AYDIN
Altostratus
to do list we add secodary URL for each country. firstly, modify iRule like that:
when HTTP_REQUEST { set countryCode [whereis [IP::client_addr]] if {[HTTP::uri] contains "pid=search"} { append countryCode "2" } set redir [class match -value -- $countryCode contains country-redirect] if { $redir ne "" } { HTTP::redirect $redir } else { HTTP::redirect "http://default.example.com/" } }
add a secodary url for each country in the data group:
ltm data-group internal country-redirect { records { AU { data http://www.example1.com/ } AU2 { data http://www2.example1.com/ } CR { data http://www.example2.com/ } CR2 { data http://www2.example2.com/ } MX { data http://www.example2.com/ } MX2 { data http://www2.example2.com/ } UK { data http://www.example1.com/ } UK2 { data http://www2.example1.com/ } US { data http://www.example1.com/ } US2 { data http://www2.example1.com/ } } type string }
Hi Dean,
you may take a look to the two iRules below. They are outlining two different coding styles to achive what you've asked for...
"AND NOT with NE" Syntax
when CLIENT_ACCEPTED { if { [set country [whereis [IP::client_addr]]] eq "" } then { set country "empty" } } when HTTP_REQUEST { set redir [class match -value -- $country contains country-redirect] if { ( $country eq "AU" ) and ( $redir ne "" ) and ( [URI::query [HTTP::uri] "pid"] ne "search" ) } then { Do whatever you want... } elseif { $redir ne "" } then { HTTP::redirect $redir } else { HTTP::redirect "http://default.example.com/" } }
"AND with EQ" Syntax
when CLIENT_ACCEPTED { if { [set country [whereis [IP::client_addr]]] eq "" } then { set country "empty" } } when HTTP_REQUEST { set redir [class match -value -- $country contains country-redirect] if { ( $country eq "AU" ) and ( $redir ne "" ) and not ( [URI::query [HTTP::uri] "pid"] eq "search" ) } then { Do whatever you want... } elseif { $redir ne "" } then { HTTP::redirect $redir } else { HTTP::redirect "http://default.example.com/" } }
Cheers, Kai
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