Forum Discussion
shawno_84086
May 30, 2007Nimbostratus
Realtional URI rewrites
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...
Deb_Allen_18
Jun 14, 2007Historic F5 Account
Hi Shawn --
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.HTH
/deb
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