Forum Discussion
Colin_Walker_12
Jan 20, 2011Historic F5 Account
Aaron's got the idea for sure, and gave you the expression you'll need to get the end of the URI. All you need to do is perform the check on the response code and do the class lookup.
So what you're looking for is something like:
when HTTP_REQUEST {
set uri_token [string range [HTTP::path] [expr {[string last / [HTTP::path]] + 1}] end]
}
when HTTP_RESPONSE {
if {[HTTP::status] == 404} {
set red_uri [class match -value $uri_token equals class_name]
HTTP::redirect $red_uri
}
}
This would have a class called "class_name" with a format like:
class_name {
"man-in-band" := "http://www.xyz.com/event/98473/man-in-band",
"band-in-park" := "http://www.xyz.com/venue/9383783/band-in-park"
}
Of course, if you wanted to re-use the host name or other parts of the URL so you don't have to specifically set the entire URL to redirect to in the class, you could do that, but this should show you how the idea works, anyway.
Colin