Forum Discussion
lori_54451
Nimbostratus
May 01, 2007Using iruel for redirects
I just inherited a web hosting farm that is experencing issues contolling thier targeted urls within thier web application. They have been living with this issue in thier previous hosting site for 2-3 years I suggested we use the bigip to perform these targeted url redirects. We already successfully use iRules to do redirects for all of our ecommerce websites, seems like a good fit. We were all busy singing joyous songs of celebration when they dropped the bomb! They have almost 600 targeted urls. The most if/else url inspections I do currently in a single iRule is 15. So, my question is simply, what should I be thinking about if i'm going to build an iRule that has 600 url inspection lines in it.
14 Replies
- Deb_Allen_18Historic F5 AccountPlease, by all means, continue singing, and let's all think happy thoughts about the "findclass" command...
:D
I have some new findclass URI mapping tricks up my sleeve that I haven't yet made pretty enough to post on the CodeShare, and this may be just the kick I need to make that happen.
If you can please provide some specific examples of the URI's for which you need to perform redirects, I'm sure we can get you going.
The critical details are going to be the "inconsistencies" or variations re: parts of the URI that must be evaluated to choose the correct redirect target, for example::
redirect /dir2/thisfileonly to X
redirect /dir1/dir2/* to Y
redirect /dir1/ to Z
more later
/deb - lori_54451
Nimbostratus
This is the current rule that i am testing,
when HTTP_REQUEST {
if { [HTTP::uri] eq "/histology" and [HTTP::host] == "www.thermo.com" } {
HTTP::redirect http://www.thermo.com/com/cda/category/category_lp/0,2152,53,00.html
} else {
use pool www.thermo.com-pool_80
}
}
so basically, I will have 600 'if's' all with a different uri string to match and redirect to a specific page.
if { [HTTP::uri] eq "/histology" and [HTTP::host] == "www.thermo.com" } {
HTTP::redirect http://www.thermo.com/com/cda/category/category_lp/0,2152,53,00.html - Deb_Allen_18Historic F5 AccountWell, I'm sort of trying to edge you away from the "death by 600 if's" version of the iRule you could create... but to do so, we'll need to know if the decision will always be based on the hostname and first directory, as in the example you give above, or will there be some variation in what needs to be evaluated -- different hostnames, different of directories, etc.
/deb - lori_54451
Nimbostratus
always based on hostname and 1st directory. - Deb_Allen_18Historic F5 AccountSure, then, that's pretty straightforward:
Create a class list containing your request and redirect details in 2 columns, separated by a space -- hostname/firstdir in one, then the redirect target in the other.
Then create this iRule an apply to the virtual server:class myRedirects { "www.thermo.com/histology http://www.thermo.com/.../0,2152,53,00.html" "www.whatever.com/dir1 http://newhost/newuri" }rule URIredirects { when HTTP_REQUEST { set req "[HTTP::host]/[getfield [HTTP::uri] "/" 2]" set redir [findclass $req $::myRedirects] if {$redir !=""}{ HTTP::redirect $redir } } }
/deb - lori_54451
Nimbostratus
Thats pretty sweet. Is the class list stored in memory, do i need to worry about memory consumption - lori_54451
Nimbostratus
stupid question, hpw do i create the class list. I read some doc, looks like i need the webacclerator module, which i do not have - Deb_Allen_18Historic F5 Accountoh, sorry, they are still called classes in the config, but I keep forgetting they are now called "Data Group Lists" in the GUI and doc.
You can just browse in the GUI to Local Traffic/iRules, click on the Data Group List tab, and create a new list of type "String". Add your list, one row at a time, with a space separating the host/uri and the redirect (GUI will add the double quotes for you).
Class lists are stored in the bigip.conf file, and are loaded into memory with the rest of the config. We have customers using very large class lists with simple iRules such as this with minimal performance impact.
/deb - lori_54451
Nimbostratus
thanks. is there a trick to adding the 600 or so strings, besides hand editing the conf file..? - Deb_Allen_18Historic F5 AccountYou can edit the config file, in which case you'd need to just follow this format:
Once the conf file is saved, load into memory with a manual config reload ("bigpipe load" at the command line). Once the class is created, indivudual members can be updated on the fly in the GUI.class myRedirects { "hydration.company.com http://www2.co.com/hydration.html" "nhra.com http://www.us.company.com/nhraHome.do" "redirect.co.com http://www.company.com/" "thecompany.com http://www.thecompany.com/" }
If you won't need to be updating it on the fly from the GUI, you can create what's called an "external class" which uses a separate text file to store the data. To do so, create a new text file in the /config filesystem (to sync automatically) in the following format:
and create a class of type "External" referencing this file. Note the trailing comma on each line, including the last. Changes to the file require a manual config reload before they take effect ("bigpipe load" at the command line)."hydration.company.com http://www2.co.com/hydration.html", "home.company.com http://www.us.company.com/Home.do", "redirect.co.com http://www.company.com/", "thecompany.com http://www.thecompany.com/",
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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