Forum Discussion
Brian_Kenworthy
Nimbostratus
Feb 10, 2011HTTP>HTTPS Redirect to different domain
Hi all, this should be pretty simple....hopefully.
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:
http://xxx.domainA.com to https://xxx.domainB.com
http://yyy.domainA.com to https://yyy.domainB.com
http://zzz.domainA.com to https://zzz.domainB.com
Is there any easier way to do this besides using a switch command for ever sub domain? I.E.
when HTTP_REQUEST {
switch [HTTP::host] {
xxx.domainA.com {
HTTP::redirect "https://xxx.domainB.com"
}
yyy.domainA.com {
HTTP::redirect "https://yyy.domainB.com"
}
etc...
Thanks in advance for the help!
- Chris_Miller
Altostratus
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? - Brian_Kenworthy
Nimbostratus
Thanks for the response Chris, I am running 10.2.0 HF2. - Chris_Miller
Altostratus
Sure.when HTTP_REQUEST { if { [class match [HTTP::host] eq domainredirects] } { HTTP::redirect "https://[class search - value domainredirects eq [HTTP::host]]" } }
- hoolio
Cirrostratus
Nice suggestion Chris. You could save the second lookup by returning the name and value in the first lookup. Here's an untested example:when HTTP_REQUEST { set lookup [class search -element domainredirects equals [string tolower [HTTP::host]]] if { [llength $lookup] == 2 } { HTTP::redirect "https://[lindex $lookup 2][HTTP::uri]" } }
- Colin_Walker_12Historic F5 Account@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. ;)
- Brian_Kenworthy
Nimbostratus
Thanks guys, I implemented Chris' solution and it worked like a charm, but when I tired Aaron's it did not work for some reason :( - hoolio
Cirrostratus
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]" } }
- if you always know that you want to move domainA.com to domainB.com, you could do something more generic like this
That would redirect all requests to XXX.domainA.com to XXX.domainB.com retaining the URIs.when HTTP_REQUEST { if { [HTTP::host] ends_with "domainA.com" } { HTTP::redirect "https://[getfield [HTTP::host] "." 1].domainB.com[HTTP::uri]" } }
- yihwen_100254
Nimbostratus
Hi Joe - yihwen_100254
Nimbostratus
Posted By Joe on 02/10/2011 01:44 PMwhen HTTP_REQUEST { if { [HTTP::host] ends_with "domainA.com" } { HTTP::redirect "https://[getfield [HTTP::host] "." 1].domainB.com[HTTP::uri]" } }
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects