Forum Discussion
The old 'Operation not supported. Multiple redirect/respond invocations not allowed' chestnut
Hi,
So this iRule kind of evolved and it seems it always had the multiple invocation error issue. So I changed the logic to break out the final default https redirect. The problem is it clashes with the default on the switch. The problem is that the site is really convoluted and I cannot get rid of the final redirect and without the default on the switch I lose the redirect for http://www.bobsite.co.uk/ to https. I don't see why? I should be bale to remove the default statement on the switch and just hit the else at the end.
when CLIENT_ACCEPTED {
set DEFAULT_POOL [LB::server pool]
}
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"
}
mediaroom.bobsite.co.uk
} elseif {$HOST eq "mediaroom.bobsite.co.uk"} {
HTTP::respond 301 Location "https://www.bobsite.co.uk/about/media-room"
Convert the hostname "bobsite.co.uk" or "bobsite.com" to "www.bobsite.co.uk"
} elseif { (($HOST eq "bobsite.co.uk") || ($HOST contains "bobsite.com")) } {
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"
}
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]" }
}
If no match send to https
} else {
HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
}
unset DEBUG
unset LOG_PREFIX
unset HOST
unset URI
}
If anyone can spot what's going on that would be great. I want to avoid breaking the switch into if statements.
Thanks
4 Replies
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
- Mark_58017
Nimbostratus
Of course didn't stick the switch in a condition!!! Thanks for spotting that. I was looking into the TCP return but couldn't spot the issue above.
I'm blaming that one on first day back :)
Thanks again
- Hey Marc, you're welcome and also wishing a successful new year! ;-) Cheers, Kai P.s.: Its not a "TCP return" (does not exist), its a just the TCL "return" command to abort the current iRule processing after each single instance of the "HTTP::respond" command.
- Mark_58017
Nimbostratus
Of course didn't stick the switch in a condition!!! Thanks for spotting that. I was looking into the TCP return but couldn't spot the issue above.
I'm blaming that one on first day back :)
Thanks again
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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