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 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.
eg:
OLD NEW
abc xyz
bcd wxy
and i would like them to perform as such:
www.site.com/abc > www.site.com/xyz
www.site.com/bcd > www.site.com/wxy
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.
Thank you for your help!
Shawn
- JRahmAdminI couldn't quite infer whether those mappings are static or dynamically generated, but if they are static, you can easily create a class for that:
class myURImappings { "abc xyz" "bcd wxy" "cde vwx" "def uvw" }
when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] starts_with $::myURImappings] } { HTTP::respond 301 Location "http://www.mydomain.com/[findclass [string tolower[HTTP::uri] $::myURImappings " "]" } }
- shawno_84086NimbostratusThank you.
- JRahmAdminThere 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.
Posted By citizen_elah on 05/31/2007 6:23 AM
class myURImappings { "abc xyz" "bcd wxy" "cde vwx" "def uvw" }
when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] starts_with $::myURImappings] } { HTTP::respond 301 Location "http://www.mydomain.com/[findclass [string tolower[HTTP::uri] $::myURImappings " "]" } }
/aaa/foo -> /ZZZ/foo
- Wil_Schultz_101NimbostratusRumor 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 😄
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/abc*" { HTTP::respond 301 Location "http://www.mydomain.com/xyz" } "/bcd*" { HTTP::respond 301 Location "http://www.mydomain.com/wxy" } "/cde*" { HTTP::respond 301 Location "http://www.mydomain.com/vwx" } "/def*" { HTTP::respond 301 Location "http://www.mydomain.com/uvw" } } }
- JRahmAdminForgot the leading slash on my class example, good catch, Joe. I did assume the requirement was a URI starting with the pattern, not containing it.
- shawno_84086NimbostratusThere is really no simple correlation between the previous URIs and the new ones. The previous ones used named IDs and the new ones use numbered ids.
- shawno_84086NimbostratusThis irule is missing a close bracket so I added it, and now my irule is:
when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri]] starts_with $::redirect] } { HTTP::respond 301 Location "http://www.mydomain.com/[findclass [string tolower [HTTP::uri]] $::redirect]" } }
- Deb_Allen_18Historic F5 AccountHi Shawn --
class pCatIDs { "$ProductCategory1 126" "$ProductCategory2 129" } class cCatIDs { "$CategoryDefinition1 4294959927+20" "$CategoryDefinition2 4294959927+26" "$CategoryDefinition3 24+4294959919" "$CategoryDefinition4 36" }
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.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" } }
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