Habib_Ulla_Khan
Oct 19, 2017Nimbostratus
Consolidate irule
Hi All, On one of the VIP we have multiple irules. These irules were added on demand request from app owners and as time elapsed. we ended up with having multiple irule with multiple HTTP_REQUEST check . Due to which now we are getting lot of errors, functionality is working as of now. But support says it may not sometimes. Hence a precautionary measure, i am consolidating irules mentioned into one. Experts out there if possible help me. Below are the irules.
Code
Irule 1:
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "www.xyz.com") || ([string tolower [HTTP::host]] equals "originwww.xyz.com") || ([string tolower [HTTP::host]] equals "xyz.com") } {
switch -glob [string tolower [HTTP::uri]] {
"/en-12/*"
"/en-34/*"
"/en-56/*"
"/en-78/*"
"/content/global/aa/*" -
HTTP::redirect "https://[HTTP::host]/en/homepage.html"
}
"*-country*" -
"*-country1*" -
"*-country2*" -
"*-country3*" -
"*-country4*" -
"*-country5*" -
"*-country6*" -
"*-country7*" -
"*-country8*" -
"*-country9*" -
"*-country10*" -
"*-country11*" -
"*-country12*" -
"*-country13*" -
"*-country14*" -
"*-country15*" -
"*-country16*" -
"*-country17*" -
"*-country18*" -
"*-country19*" -
"*-country 20*" {
set arcom_uri [substr "[string tolower [HTTP::uri]]" 1 "/"]
if { ($qrcom_uri contains "-") || ($qrcom_uri equals "en") }{
log local0. "NEW: $arcom_uri"
HTTP::redirect "http://[HTTP::host]/$arcom_uri/discover.html"
} else {
set old_qrcom_uri [substr "[string tolower [HTTP::uri]]" 1 5]
log local0. "OLD: $old_arcom_uri"
HTTP::redirect "http://[HTTP::host]/$old_arcom_uri/destinations.page"
}
}
}
}
}
Code
IRULE 2
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] eq "xyz.com"}{
switch -glob [string tolower [HTTP::uri]] {
"/en/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/cntent/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/apps/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/etc/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/ar/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/libs/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/bin/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
"/en-*/*" {
HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}
}
return
}
switch -glob [string tolower [HTTP::uri]] {
"/en/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/cntent/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/apps/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/etc/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/ar/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/libs/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
"/bin/*" {
HTTP::respond 302 "https://[HTTP::host][HTTP::uri]"
}
} }
Code
IRULE 3:
when HTTP_REQUEST {
if {[HTTP::header exists True-Client-IP]}{
if {[HTTP::header exists X-Forwarded-For]}{
HTTP::header remove X-Forwarded-For
HTTP::header insert X-Forwarded-For [HTTP::header True-Client-IP]
} else {
HTTP::header insert X-Forwarded-For [HTTP::header True-Client-IP]
}
} else {
if {[HTTP::header exists X-Forwarded-For]}{
HTTP::header remove X-Forwarded-For
HTTP::header insert X-Forwarded-For [IP::client_addr]
} else {
HTTP::header insert X-Forwarded-For [IP::client_addr]
}
}
}
Code
IRULE 4:
when HTTP_REQUEST {
if { (([HTTP::host] contains "abc.com") or ([HTTP::host] contains "www.abc.com")) } {
HTTP::redirect "https://www.xyz.com/en/Privilege-Club.html"
}
elseif { (([HTTP::host] equals "abc.ch") or ([HTTP::host] equals "www.abc.ch")) } {
HTTP::respond 301 Location "http://www.xyz.com/ch"
}
elseif { (([HTTP::host] equals "abc.ca") or ([HTTP::host] equals "www.abc.ca")) } {
HTTP::respond 301 Location "http://www.xyz.com/qa"
}
}
Code
IRULE 5:
when HTTP_REQUEST {
if {([HTTP::uri] contains "credit-card-verification.page")||([HTTP::uri] contains "facebook.page")}{
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}