Forum Discussion
Various rewrites/redirects on one VIP
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:
olddomain.com
newdomain.com newforum.newdomain.com oldforum.olddomain.comI 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
}
}
}
}
11 Replies
- JRahm
Admin
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) - giltjr
Nimbostratus
I can see why you are getting loops. Take your first if:
if { [HTTP::query] contains "TID=" } { HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]" return }
Since you are not checking for a host name it will match both "oldforum.olddomain.com" and "newforum.newdomain.com"
I would do something like this to start with:
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. } - Joe_Pipitone
Nimbostratus
We are doing a bit of both - rewriting the domain, and redirecting as well. - Joe_Pipitone
Nimbostratus
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. }- JRahm
Admin
yep, nesting if statements is absolutely acceptable.
- Joe_Pipitone
Nimbostratus
Great. One last question - I have used conditional statements before, for example:
if domain name is domain.com OR domain2.com
do stuffFor some reason, this syntax is not being accepted after reviewing logs. Any ideas?
elseif {[HTTP::host] ends_with "domain.com" - "domain2.com"} {- Joe_Pipitone
Nimbostratus
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.
- giltjr
Nimbostratus
I don't think the the statement
"{[HTTP::host] ends_with "domain.com" - "domain2.com"}"Is not valid. Now the following is:
"{[HTTP::host] ends_with "domain.com" OR [HTTP::host] ends_with "domain2.com"}"I would have to test you might be able to do:
"{[HTTP::host] ends_with ("domain.com" OR "domain2.com")}" - Joe_Pipitone
Nimbostratus
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 } } } } - Kevin_Stewart
Employee
Small typo I think, but here's another version:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "*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]" } elseif { [HTTP::query] contains "FID=" } { HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]" } elseif { [HTTP::query] contains "C=" } { HTTP::redirect "http://newforum.newdomain.com/default.aspx?g=forum&c=[URI::query [HTTP::uri] C]" } return } "*newdomain.com" - "*olddomain.com" { This needs to catch newdomain.com/uri or olddomain.com/uri and redirect if { [string tolower [HTTP::uri]] contains "secure" } { HTTP::redirect "http://newdomain.com/Issues/2014/04/some-page.aspx" } elseif { [string tolower [HTTP::uri]] contains "secure2" } { HTTP::redirect "http://newdomain.com/Issues/2014/04/some-other-page.aspx" } } } } - giltjr
Nimbostratus
Try the following. I think you had some { } out of order and you had a "else {if" when a elseif was better.
domain1, domain2, and forum rewrites when HTTP_REQUEST { if {[HTTP::host] == "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 } elseif { [string tolower [HTTP::uri]] contains "secure2" } { HTTP::redirect "http://newdomain.com/Issues/2014/04/some-other-page.aspx" return } } }
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