Forum Discussion
Don_Noel_23994
Nimbostratus
May 10, 2006HTTP Redirects
I am looking to create an iRule that does redirection based off a class list. Below is a break down of the requirements. There was an earlier attempt to put an iRule together and it is located at the bottom. Thanks for all input.
Rule Purpose:
Redirects iRule based on class lists. A Virtual Server with a designated iRule that accomplishes a simple redirect based on the match of ::host to a class list, if initial match fails, a second statement does a comparison of the TLD of the ::host to determine which TLD is intended and redirects to a static list of country-based search pages, else, in final case, it redirects to a general search site.
Order of Operation:
Site1.site.com is CNAME’d to redirects.company.co.jp a Virtual Server assigned to the iRule Site1.site.com comes to the iRule, host is extracted and compared to a list.
a)Match is found, redirect to matched pair.
b)Match is not found, move to next comparison site1.site.com matches no site in the first list, and is sent to the second list.
a)TLD is extracted and user is redirected to country specific search page.
b)TLD is extracted and not found, user is redirected to general search page.
Logistical Issues:
WWW is often pre-pended to a URL, in the existing case both the www.site.com and site.com are written as CNAME into the DNS configuration, we would like to break that configuration and CNAME www to site.com base URL to avoid confusion, and additional entries in the match list. In the case of www, where it wouldn’t be in the list, the parsing of ::host would have to be aware and take appropriate action.
Example Rule:
This rule is an example, based on information gleaned from devcentral and a thread asking for recommendations.
It is also incorrect, as it uses getfield for the first else case on which a www.site.co.uk would return co as a result and not uk as intended, it would probably need to use ends_with or some similar operator, but I didn’t get to that part.
It also does not account for the www parsing issue identified above.
class myRedirects { "site1.site.com site1a.site.com.tw"
"site2.site.com site2.othersite.co.hk"
"site3.othersite.com site1.site.co.jp"
"site4.site.com site5.othersite.co.jp\boo.asp"
"site3.site.com site5.othersite.cn\woo.asp"
}
class mySearchs {"uk site.co.uk/search.asp"
"jp site.co.jp/search.asp"
"tw site.com.tw/search.asp"
}
when HTTP_REQUEST {
set newDom [findclass [HTTP::host] $::myRedirects " "]
if { [string length $newDom] >= 1}
{
HTTP::redirect $newDom
} else {
set myCatch [findclass [getfield [HTTP::host] "." 3] $::MySearchs " "]
if { [string length $myCatch] >= 1}
{
HTTP::redirect $myCatch
} else {
HTTP::redirect "http://mysearch.com"
}
}
}
- Deb_Allen_18Historic F5 AccountHi Don --
generates the following output:May 10 15:59:46 tmm tmm[1043]: Rule : uklog local0. [domain www.company.co.uk 1]
generates the following output:May 10 15:59:46 tmm tmm[1043]: Rule : company.co.uklog local0. [findstr www.company.co.uk "www." 4]
if {[HTTP::host] starts_with "www." }{ log local0. [findstr www.company.co.uk "www." 4] }
- Deb_Allen_18Historic F5 Accountoops, I pasted the wrong commands for my example.
- Don_Noel_23994
Nimbostratus
Hi Deb, thank you for the response, I will test this and let you know how it works out.
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