I am currently burning up 3 VIPs to get all these redirects and rewrites working, however I’d like to efficiently combine the iRule, and point all 3 domains to the same VIP and accomplish the same thing. Having some issues and there are redirect loops occurring.
I have 2 domains, and 2 subdomains, which I’ve masked as:
I need to allow all traffic to newdomain.com, and newforum.newdomain.com. This iRule needs to catch all traffic going to olddomain.com, append the URI, and rewrite to newdomain.com. I also have to catch all forum requests, and rewrite the domain and path. This is already working on a separate VIP. I tried catching both www.olddomain.com and olddomain.com with an asterisk, but it doesn’t seem to work. If anyone has any ideas on what I may be missing, please let me know. Thank you!
Rewrites for 3 separate domains on one VIP. Also rewrites forum requests from old forum to new forum
when HTTP_REQUEST {
This needs to catch oldforum.olddomain.com and rewrite to newforum.newdomain.com
if { [HTTP::query] contains "TID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
return
}
if { [HTTP::query] contains "FID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
return
}
if { [HTTP::query] contains "C=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
return
}
This needs to catch newdomain.com and analyze URI
if { [string tolower [HTTP::uri]] contains "somestring" } {
HTTP::redirect "http://newdomain.com/some/path/somepage.aspx?eofseckey=233729AF8"
return
}
This needs to catch newforum.newdomain.com on port 80, append URI, and redirect to port 443
if { ([HTTP::host] eq "oldforum.olddomain.com") } {
switch -glob [HTTP::host] {
"/" { HTTP::redirect "https://newforum.newdomain.com" }
default { HTTP::redirect "https://newforum.newdomain.com[HTTP::uri]" }
}
}
This needs to catch various requests to olddomain.com and rewrite to newdomain.com
if { ([HTTP::host] contains "olddomain.com") } {
switch -glob [HTTP::host] {
"/" { HTTP::redirect "http://newdomain.com" }
default { HTTP::redirect "http://newdomain.com[HTTP::uri]" }
"/oldpath/path/oldpage-2013.aspx" {
HTTP::redirect "http://newdomain.com/new-path/newpage.aspx"
return
}
"/faq*" {
HTTP::redirect "http://another.domain.com/some/path/FAQ.pdf"
return
}
}
}
}
you say rewrite in your explanation, but are using redirect in your iRule. Can you clarify what the objective is? Do you want to rewrite (don’t change the client experience) or redirect (move clients to new domain…they will see this change in the browser)
if {[HOST::name] ends_with "newdomain.com"} {
Stuff do do when domain is "newdomain.com"
}
elseif {[HOST::name] ends_with "olddomain.com"} {
Stuff to do when domain is "olddomain.com"
} else {
stuff do do in case host name ends with something we did not expect.
}
Are you saying I can nest if statements within another if statement?
if {[HOST::name] ends_with "newdomain.com"} {
Stuff do do when domain is "newdomain.com"
}
if { [HTTP::query] contains "TID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
return
}
if { [HTTP::query] contains "FID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
return
}
if { [HTTP::query] contains "C=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
return
}
}
elseif {[HOST::name] ends_with "olddomain.com"} {
Stuff to do when domain is "olddomain.com"
} else {
stuff do do in case host name ends with something we did not expect.
}
Wondering if it may be more efficient to do it this way, rather than inserting another if statement - I have to perform the same redirect for both domains.
Still having trouble getting this rule to work. The first part works, where it redirects the old forum topics and threads, however it doesn’t seem to work its way down and catch newdomain.com or olddomain.com. I setup logging, which is one of the reasons why I know its not getting past the first batch of if statements.
domain1, domain2, and forum rewrites
when HTTP_REQUEST {
if {[HTTP::host] ends_with "oldforum.olddomain.com"} {
This needs to catch oldforum.olddomain.com and rewrite to newforum.newdomain.com
if { [HTTP::query] contains "TID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
return
}
if { [HTTP::query] contains "FID=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
return
}
if { [HTTP::query] contains "C=" } {
HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]"
return
}
elseif { ([HTTP::host] ends_with "newdomain.com") or ([HTTP::host] ends_with "olddomain.com") } {
This needs to catch newdomain.com/uri or olddomain.com/uri and redirect
log local0. "Hostname is [HTTP::host]" }
if { [string tolower [HTTP::uri]] contains "secure" } {
HTTP::redirect "http://newdomain.com/Issues/2014/04/some-page.aspx"
return
}
else {
if { [string tolower [HTTP::uri]] contains "secure2" } {
HTTP::redirect "http://newdomain.com/Issues/2014/04/some-other-page.aspx"
return
}
}
}
}