Forum Discussion
Darren_Person_2
Nimbostratus
Nov 03, 2006iRule URL Rewrite for Multiple domains
Can someone explain how to approach this problem?
I have multiple domains that each need to 302 redirect back to their primary's:
For example,
i have:
www.test.com ...
Nov 06, 2006
There was a good contribution to the wiki a while back outlining general guidelines on how to write fast iRules
http://devcentral.f5.com/Wiki/default.aspx/iRules/HowToWriteFastRules.html
Click here
It states in there that switch statements are better than matchclass for 100 items or less. While that may be true, manageability is a major issue to consider. Including everything in a class, especially when you are mapping domains to uris, is much more usable and easy to update.
If I were you, I'd go with the class approach and either with the matchclass or findclass calls (matchclass if you just want to see if an element is present, findclass if you want to extract the element and possible other subcomponents).
This code illustrates how you can embed domains and redirect urls into a class and access them with the findclass command:
class domain_check {
"www.test.com primary.com"
"test.com primary.com"
"www.xyz.com secondary.com"
"xyz.com secondary.com"
}
--- Begin iRule ---
when HTTP_REQUEST {
set redir [findclass [HTTP::host] $::domain_check " "]
if { $redir ne "" } {
HTTP::redirect "http://$redir[HTTP::uri]"
}
}
The findclass will look for the HTTP::host value and return the second token in the list item (separated by spaces).
Your iRule remains quite simple and all your management is done within the data group.
If you have the same domain you are mapping to, just use the matchclass which returns a boolean if a match is found.
-Joe
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