I am completely new to irules and I would like some validation, or perhaps a better way to do what I want.
I am deploying a new website that uses a completely new set of URIs. All of the previous URIs do not exist on the new site, but the data is still there using a completely different uri. There are numerous links to these pages out on the web and we would like to preserve their funcitonality.
So, I have a table of begin values and end values.
I have read that you can not use relational data in classes creating irules, so I am guessing that I need an irule looking like this:
when HTTP_REQUEST
{ if { [HTTP::uri] contains "/abc" } { HTTP::respond 301 Location "http://www.mydomain.com/xyz" }
{ if { [HTTP::uri] contains "/bcd" } { HTTP::respond 301 Location "http://www.mydomain.com/wxy" }
}
Let’s just say I have 1000 such URLs that I need to redirect like this and I am not sure of the performance impact of such a large irule, not to mention the managability of it.
There certainly will be an impact, but to what degree depends on several factors, including device hardware, traffic patterns, where the match occurs in the class, etc. I haven’t tested anything to this scale, so I’d recommend doing that so you know where your performance thresholds are.
That won’t quite work because the value of HTTP::uri will always start with a slash. Also, your findclass call is assuming that the URI equals the value in the class, but the originally supplied code used the contains operator.
We don’t have measurements for class lists of 10000+ entries, but you’ll have to expect that it will have a performance impact (you can’t get 10000 string comparisons for free).
If you can supply some real examples of what you are trying to map from/to there might be a way to use some tricks to limit the number of mappings needed. For instance, if you need to map:
/aaa/foo → /ZZZ/foo
/aaa/bar → /ZZZ/bar
…
Then you can do some string splitting and just extract the first element of the URI and look that up, then dynamically build the redirect/respond retaining the original trailing section of the URI. But without examples/requirements I don’t know if that will work for you.
Rumor has it that switches are faster, I don’t know this for a fact, however I do use switches wherever possible and have not run into any problems yet
This was really just a guess at where the close bracket should go, and I’m not sure why there were the 2 trailing quotation marks, but I tried with and without them, to no avail.
The irule loaded OK in the gui, and I have added it as a resource to my virtual server, but it does not seem to be doing anything. Examination of http traffic does not show a redirect taking place.
I contacted support and they said they are unable to help me and that devcentral is the correct resource.
I think the best approach would be to rewrite the path and each query parameter separately, then redirect using the reconstructed URI.
To re-write the query parameters, I’d start by creating 2 classes, one containing the map for pCatID and the other for cCatID:
class pCatIDs {
"$ProductCategory1 126"
"$ProductCategory2 129"
}
class cCatIDs {
"$CategoryDefinition1 4294959927+20"
"$CategoryDefinition2 4294959927+26"
"$CategoryDefinition3 24+4294959919"
"$CategoryDefinition4 36"
}
The path is static, so no class required there. Here’s the iRule:
when HTTP_REQUEST {
only process the desired requests
if {[HTTP::path] == "/productgridview.aspx" }{
set qstring [HTTP::query]
log local0. "original qstring = >$qstring<"
find match for pCatID, replace if found
set pCatID1 [findstr "pCatID=" [HTTP::query] 7 "&"]
if {$pCatID1 != ""}{
set pCatID2 [findclass $pCatID1 $::pCatIDs " "]
if {$pCatID2 != ""}{
set qstring [string map [list $pCatID1 $pCatID2] $qstring]
log local0. "qstring after pCatID relacement = >$qstring<"
}
}
find match for cCatID, replace if found
set cCatID1 [findstr "cCatID=" [HTTP::query] 7 "&"]
if {$cCatID1 != ""}{
set cCatID2 [findclass $cCatID1 $::cCatIDs " "]
if {$cCatID2 != ""}{
set qstring [string map [list $cCatID1 $cCatID2] $qstring]
log local0. "qstring after cCatID relacement = >$qstring<"
}
}
HTTP::respond 301 Location "http://[HTTP::host]/Pages/ProductGridView/ProductGridView.aspx$qstring"
}
}
I think the string map/list construct will handle the “$” in the query parameters, if not you might have to do some special handling of that character -- added some logging to help out there, so look in the log for those values or runtime errors regarding non-existent variables.