Forum Discussion
Bob_10976
Nimbostratus
Apr 24, 2008Rewrite iRule to replace ISAPI rewrite
Let me first start off saying I'm very new to the F5 so sorry if my questions seem nebie'ish.
Our current environment we use an ISAPI Rewrite in IIS to redirect request to the correct location. I've been asked to remove that as a web server function and put it on the load balancer. From what I understand that possible via iRules, however I have no idea how to create such a rule. Anyone have something out there that does this already or maybe point me in the right direction.
Thanks in advance,
Bob
4 Replies
- hoolio
Cirrostratus
Hi Bob,
You can definitely use an iRule to send a redirect back to the client, or rewrite the Location header in a redirect that the application sends. If you can provide more specifics on what you're trying to rewrite from/to, plenty of people around here could help with an example or two.
Aaron - ivy62798_39340
Nimbostratus
I'm looking for this example. If you could provide, that would be great. Here are some more details on what we are doing.
We use IIS 6, so there is of course no wildcarding available when setting up a site. We have template sites that all use their own "subdomain". So, for example, let's say we are dealing with the domain mydealers.com
Each dealer would have it's own subdomain that would be dealer1.mydealers.com, dealer2.mydealers.com.......now, as we know, I could setup each and every subdomain within IIS but there are hundreds and always adding more. In order to get around this, we now use ISAPI Rewrite but now we have an F5 LTM (YEAH!).
All the sites use the same code base under the one IIS entry. We just use the subdomain name to make sure that dealers inventory shows up on the site and not some other dealer.
How can I do the same thing with the F5 as I do with ISAPI Rewrite.
Thanks! - Bob_10976
Nimbostratus
A couple of examples from our rewrite rule is below, honestly I still don't completely understand it, my dev guy wrote these, I just put them in place, hope it helps a bit...
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/helpcenter/" } {
HTTP::uri "/helpcenter/Pages/default.aspx"
}
elseif { [string tolower [HTTP::uri]] equals "/helpcenter/livehelp.htm" } {
HTTP::uri "/Pages/livehelp.aspx"
}
elseif { [string tolower [HTTP::uri]] starts_with "/policy/privacy.htm" } {
HTTP::uri "/Pages/privacy.aspx"
}
elseif { [string tolower [HTTP::uri]] starts_with "/policy/security.htm" } {
HTTP::uri "/Pages/security.aspx"
}
}
Also is a few examples from our Redirect rule:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.mydomain.com" } {
HTTP::respond 301 Location http://mydomain.com[HTTP::uri]
}
elseif { ([string tolower [HTTP::uri]] equals "/default.htm") || ([string tolower [HTTP::uri]] equals "/default.html") } {
HTTP::redirect http://mydomain.com/
}
elseif { [string tolower [HTTP::uri]] starts_with "/newsroom" } {
HTTP::respond 301 Location http://test.mydomain.com/newsroom/[substr [HTTP::uri] 10 ]
}
elseif { [string tolower [HTTP::uri]] starts_with "/g2p" } {
HTTP::redirect http://test.mydomain.com/g2p/[substr [HTTP::uri] 5 ]
}
elseif { [string tolower [HTTP::uri]] starts_with "/eventcal" } {
HTTP::respond 301 Location http://test.mydomain.com/eventcal/[substr [HTTP::uri] 10 ]
Good luck..
Bob - Colin_Walker_12Historic F5 AccountThose look like pretty good examples, though I might recommend the use of the switch command for a little added efficiency and, to me, ease of reading.
Colin
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
