Forum Discussion
Kai_Wilke
Jan 04, 2016MVP
HI Mark,
if this is the only iRule bound to your VS, then you could abort further iRule processing after each single HTTP::respond command by calling the return command. It would allow you to code without keeping the remaining commands in mind. Alternatively see the code below. Its now HTTP::respond collision free...
when HTTP_REQUEST {
Setting the Initial Variables
set DEBUG 0
set LOG_PREFIX [IP::client_addr]
set HOST [string tolower [HTTP::host]]
set URI [string tolower [HTTP::uri]]
if {$HOST eq "m.bobsite.co.uk"} {
if {[class match $URI starts_with m.bobsite.co.uk]} {
set URI [class match -value -- $URI starts_with m.bobsite.co.uk]
if { $DEBUG } { log local0. "$LOG_PREFIX: Redirecting to https://www.bobsite.co.uk/$URI" }
HTTP::respond 301 location "https://www.bobsite.co.uk$URI"
} else {
HTTP::respond 301 Location "https://www.bobsite.co.uk"
}
} elseif {$HOST eq "mediaroom.bobsite.co.uk"} {
mediaroom.bobsite.co.uk
HTTP::respond 301 Location "https://www.bobsite.co.uk/about/media-room"
} elseif { (($HOST eq "bobsite.co.uk") || ($HOST contains "bobsite.com")) } {
Convert the hostname "bobsite.co.uk" or "bobsite.com" to "www.bobsite.co.uk"
HTTP::respond 301 location "https://www.bobsite.co.uk[HTTP::uri]"
} elseif {$HOST eq "www.bobsite.co.uk"} {
Convert the URI based on a match in the datagroup
if {[class match $URI eq www.bobsite.co.uk_v2]} {
set URI [class match -value -- $URI eq www.bobsite.co.uk_v2]
if { $DEBUG } { log local0. "$LOG_PREFIX: Redirecting to https://$HOST$URI" }
HTTP::respond 301 location "https://$HOST$URI"
} else {
Dealing with the edge cases
switch -glob $URI {
"/2for1-london" { HTTP::respond 301 Location "https://www.bobsite.co.uk/stations-destinations/train-to" }
"/about/careers/" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/brochure/" }
"/about/careers" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/Brochure/" }
"/about/careers/faqs.aspx" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/brochure/" }
"/careers/" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/Brochure/" }
"/careers" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/brochure/" }
"/contact_us/jobs/default.aspx" { HTTP::respond 301 Location "http://www.bobsitecareers.co.uk/brochure/" }
"/livechat" { HTTP::respond 301 Location "https://webchat.bobinteractive.com/start.jsp?workgroup=vt@workgroup.livechat.bobinteractive.com&location=https://www.bobsite.co.uk/livechat" }
"/livechat/" { HTTP::respond 301 Location "https://webchat.bobinteractive.com/start.jsp?workgroup=vt@workgroup.livechat.bobinteractive.com&location=https://www.bobsite.co.uk/livechat" }
"/tasty" { HTTP::respond 301 Location "https://www.buytickets.bobsite.co.uk/buytickets/advancedsearch.aspx" }
default { HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]" }
}
}
} else {
If no match send to https
HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
}
unset DEBUG
unset LOG_PREFIX
unset HOST
unset URI
}
P.s.: The change is here..
} else { Dealing with the edge cases
Cheers, Kai