I have a simple HTTP>HTTPS redirect in place for a domain --> HTTP::redirect “https://[HTTP::host][HTTP::uri]”
We have several subdomains (~15) xxx.domainA.com, yyy.domainA.com, etc. What we would like to do now is redirect those same sub domains to a new domain:
I’d create a data group containing all the domains, check for a match, and if a match exists, use string to insert the value. Otherwise, you could use class search - value if you’re on a newer version of code. What version are you on?
You’d have a string type data group called something like “domainredirects.” In that group, you’d have a string like “xxx.domaina.com” with a value like “xxx.domainb.com.” Then, your rule would look something like this:
when HTTP_REQUEST {
if { [class match [HTTP::host] eq domainredirects] } {
HTTP::redirect "https://[class search - value domainredirects eq [HTTP::host]]" }
}
Otherwise, if your scheme is as simple as xxx.domaina.com > xxx.domainb.com, then a string command would be more efficient. All depends on how many characters you’re changing I suppose.
@Aaron - Is there a reason for returning the element rather than the value in the search? You could save the lindex lookup if you returned the value directly. A bit nit-picky I suppose but I’m more curious if there’s some reason you’re doing it that I’m not seeing rather than trying to nit pick optimizations.
I like nit-picking to get the most efficient solution :). I was being a dolt and thinking of another recent conversation where we needed the matched name and value for later logic. In this case, you just need the matched value, so something like this should work:
when HTTP_REQUEST {
set host [class search -value domainredirects equals [string tolower [HTTP::host]]]
if { $host ne "" } {
HTTP::redirect "https://$host[HTTP::uri]"
}
}
What if we have multiple prefix to the domain. whill that be reditected too. For example if we have xxx.yyy.DomainA.com this does not get routed to xxx.yyy.DomainB.com with the above rule. Am i missing anythin here.