Forum Discussion
dkinsler_23191
Nimbostratus
Jan 26, 2010Most efficient way to write this
My devs are asking me to Do many many redirects based on various mispellings our our URL's. I am worried about the extra processing of every request going through these lists of if/then statements. Is there a more processor/network friendly way to write this? Keep in mind im actually talking about adding like 30 of these, this is a small sampling. I dont want to over tax the LB or slow down my responses. Any help would be greatly appriciated.
when HTTP_REQUEST {
if { [HTTP::host] equals "connection1.net"} {
HTTP::redirect "http://www.connection1.com[HTTP::uri]"
}
if { [HTTP::host] equals "connection1.org"} {
HTTP::redirect "http://www.connection1.com[HTTP::uri]"
}
if { [HTTP::host] equals "connection1.biz"} {
HTTP::redirect "http://www.connection1.com[HTTP::uri]"
}
if { [HTTP::host] equals "connection2.com"} {
HTTP::redirect "http://www.connection1.com[HTTP::uri]"
}
if { ([HTTP::host] equals "www.connection1.org") and ([HTTP::uri] equals "/")} {
HTTP::redirect "http://www.connections1.com/folder1/home.aspx"
}
if { ([HTTP::host] equals "www.connection1.net") and ([HTTP::uri] equals "/")} {
HTTP::redirect "http://www.connection1.com/folder1/home.aspx"
}
if { ([HTTP::host] equals "www.connection1.biz") and ([HTTP::uri] equals "/")} {
HTTP::redirect "http://www.connection1.com/folder1/home.aspx"
}
if { ([HTTP::host] equals "www.connection1.com") and ([HTTP::uri] equals "/")} {
HTTP::redirect "http://www.connection1.com/folder1/home.aspx"
}
}
2 Replies
- hoolio
Cirrostratus
The most efficient option might be to get a new IP address to resolve all the alternate spellings to and then use however complicated an iRule that you want.
Else, if you need to stick with one address, you can put the real hostname first in a switch statement and the rest afterward. That way you would only do one evaluation of the host header value for the majority of requests. I don't think evaluating the host header several times in a switch statement would add that much overhead anyhow, but it's always good to try to make things as efficient as possible.when HTTP_REQUEST { Check the requested host header (set to lowercase) switch [string tolower [HTTP::host]] { "realdomain.example.com" { do nothing } "alternatespelling1.example.com" { check the URI and/or redirect request } "alternatespelling2.example.com" { check the URI and/or redirect request } default { no match, take some default action? } } }
Aaron - The_Bhattman
Nimbostratus
Hi dkinslerUser,
I suppose you could use the switch command with IF statements
Here is untested examplewhen HTTP_REQUEST { switch -glob [string tolower[HTTP::host]] { "connection1.net" - "connecton1.org" - "connection1.biz" - "connection2.com" - { HTTP::redirect "http://www.connection1.com[HTTP::uri] } default { if [HTTP::uri] eq "/" } { switch -glob [string tolower[HTTP::host]] { "www.connection1.org" - "www.connection1.net" - "www.connection1.biz" - "www.connection1.com" { HTTP::redirect "http://www.connection1.com/folder1/home.aspx" } } } } } }
Bhattman
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