Forum Discussion
Craig_17655
Nimbostratus
Aug 14, 2009iRule for Redirrecting based upon URI
I am trying to replace some apache functionality using iRules. I have the following rules set up in apache:
SetHandler matrix
SetCluster imgserver
So basically, if the URI contains .img I send the request to a different set of servers that handles the requests.
I am looking for advise as I am new to irules and have not found many examples. I think it is something like this:
when HTTP_REQUEST {
set uri [HTTP::uri]
if { $uri contains ".img" }
pool testpool2
}
else {
pool testpool
}
Any help would be greatly appreciated.
5 Replies
- The_Bhattman
Nimbostratus
Hi,
You could also write it like the following:when HTTP_REQUEST { if { [HTTP::uri] contains ".img" } { pool testpool2 } else { pool testpool } }
orwhen HTTP_REQUEST if {([HTTP::host] eq "www.yourdomain.com") and ( [HTTP::uri] contains ".img" ) } { pool testpool2 } else { pool testpool } }
Click here to see how you can change the 2 operators to suit your needs - Don't forget the "equals" between the host and www.yourdomain.com comparison.
...([HTTP::host] equals "www.yourdomain.com")...
-Joe - The_Bhattman
Nimbostratus
Thanks Joe. I don't know what I was thinking. - hoolio
Cirrostratus
You could be more specific and check for a path ending in .img:
[HTTP::path] ends_with ".img"
This handles an image with or without a query string.
Aaron - Craig_17655
Nimbostratus
Through support from F5 I found that I should use HTTP:path instead of HTTP:uri
This is why:
The issue is that the HTTP:uri command begins parsing with the slash after the hostname, then grabs the path, then the query.
From DevCentral:
HTTP::uri
* Returns the URI of the request. It does not include the protocol (http or https) or hostname, just the path and query string, starting with the slash after the hostname.
http://devcentral.f5.com/Wiki/default.aspx/iRules/HTTP__uri.html
Based on your example URL, "HTTP:uri" will return the entire line, as everything that follows the "?" character represents the query.
Try this instead:
HTTP::path
"Returns or sets the path part of the HTTP request. The path is defined as the path and filename in a request. It does not include the query string."
http://devcentral.f5.com/Wiki/default.aspx/iRules/HTTP__path.html
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