Forum Discussion
Steve_M__153836
Jul 14, 2015Nimbostratus
iRule Help - Capture URI, Modify, and Redirect
I have two sets of incoming URLs I need to pick apart and redirect based on their content. Both with the same formatting.
https://my.site.org/A/B/find-a-thing1/garbage
https://my.site.org/A/B/fin...
Steve_245_23966
Jan 12, 2016Altocumulus
Devcentral ate and destroyed my previous account so posting under this account. This is a final working version. Note the asterisks in the lines with scan commands. They can be hard to pick out of there. This article helped greatly in getting this to work: Revisiting the Scan Command.
when HTTP_REQUEST {
set URI [string tolower [HTTP::uri]]
if { $URI equals "/" or $URI equals ""} {
HTTP::respond 301 Location "https://My.site.org/mysite"
} elseif { $URI contains "find-a-thing1" and $URI contains "thing1detail" } {
scan $URI {/%*[^/]/%*[^/]/%*[^/]/%*[^/]/%[^/]/%*[^/]/} a
HTTP::respond 301 Location "https://diff.site.org/thing1/$a"
} elseif { $URI contains "find-a-thing"} {
HTTP::respond 301 Location "https://diff.site.org/thing1"
} elseif { $URI contains "find-a-thing2" and $URI contains "thing2detail"} {
scan $URI {/%*[^/]/%*[^/]/%*[^/]/%*[^/]/%[^/]/%[^/]/} b c
HTTP::respond 301 Location "https://diff.site.org/thing2/$b/$c"
} elseif { $URI contains "find-a-thing2"} {
HTTP::respond 301 Location "https://diff.site.org/thing2"
}
}
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