Forum Discussion
Jeremyah_Corner
Nimbostratus
Apr 03, 2006Big Redirects List
I've got a lengthy list of redirs that I want to use F5 to do the work with, instead of a custom ASP solution that is running currently.
The basic gist..
I've got a list:
site1 site1a
site2 site1a
site3 site1a
site4 site2a
site5 site2b
site6 site3b\widget.htm
site7 site2b\widget.asp
etc...
I was reading and I noticed a method that might be useful, such as building a class that contains this list and using a find or matchclass to compare the URI to that list and extracting the second element of that match as a http::redirect "Result"
Of course, I understand the basics of if, else, ::uri and ::redirect, what I'm missing is clues on extracting the matched pair from the class list as the element to give to the redirect string.
-- part 2, wild card redirects
In addition to having specificly site1.site.com and wanting it to go to site1a.othersite.com if all else fails in this long list I want anything .site.com to go to othersite.com\search.asp.. could this be included in the class list (at the end) and it function approprately?
6 Replies
- hoolio
Cirrostratus
To search a class and retrieve the second part of the class member, you can use findclass: - Colin_Walker_12Historic F5 AccountHoolio's right on on this one.
class myRedirects { "site1 site1a" "site2 site1a" "site3 site1a" "site4 site2a" "site5 site2b" "site6 site3b\widget.htm" "site7 site2b\widget.asp" }
[findclass [HTTP::host] $::myRedirects " "]
[findclass [getfield [HTTP::host] "." 1] $::myRedirects " "]
when HTTP_REQUEST { set newDom [findclass [getfield [HTTP::host] "." 1] $::myRedirects " "] if { [string length $newDom] >= 1 } { HTTP::redirect $newDom } else { HTTP::redirect "http://othersite.com/search.asp" } }
- Jeremyah_Corner
Nimbostratus
So, I've built two lists, a redirects, and a search list.. I'm asking find the pair based on the host address from the myRedirects list, then redirect, else (if the length of newdom is less than or equal to 1) find the third field of the host name (Based on the .) and find it in mySearchs lists then redirect to somesite in that list, else do a base redirect to a global search page.class myRedirects { "site1.site.com site1a.site.com" "site2.site.com site2.othersite.com" "site3.othersite.com site1.site.com" "site4.site.com site5.othersite.com\boo.asp" "site3.site.com site5.othersite.com\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" } } }
- Jeremyah_Corner
Nimbostratus
Bump :-) - Colin_Walker_12Historic F5 AccountThe rule looks pretty close. I'd make sure you have an open bracket before HTTP::host in your getfield command, though. Like this:
set myCatch [findclass [getfield [HTTP::host] "." 3] $::MySearchs " "]
- Jeremyah_Corner
Nimbostratus
Excellent, thanks for all the great help.
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