iRule to redirect based on uri content

Hi all,

I need a rule that redirects for a certain word within the uri--but only when that uri immediately follows the url.

In this example, “golf” is the word that should initiate the redirect, but only when it immediately follows “vw.com.”

1.) VW Models: SUVs, Sedans, Electric cars | Volkswagen => Should redirect based on rule. This is the only circumstance in which the rule should redirect

2.) http://vw.com/car/golf => Should NOT redirect based on rule

3.) http://vw.com/car/sale/golf => Should NOT redirect based on rule

In the past, we’ve used the “contains” keyword within the rule, but that won’t work here.

Thanks!

Bryan

Hi Bryan,

vw.com is the host and everything after that in the URL would be the URI.

You can get the current values using [HTTP::host] and [HTTP::uri].

It looks like you want to do something like:

if {[HTTP::uri] starts_with "/golf" }{
   HTTP::redirect http://myredirect.site.com
}

Aaron

Or, if you want to multi-host this virtual, you can add the host to the check as well:

when HTTP_REQUEST {
  if { "[HTTP::host][HTTP::uri]" starts_with "vw.com/golf" } {
    HTTP::redirect http://myredirect.site.com
  }
}

-Joe