Redirect based on position of word in uri

Hi all,

I posted a question a couple days ago, but mispoke in the question. I am posting the modified question here again as a new post.

I need a rule that redirects for a certain word within the uri--but only under specific circumstances regarding the position of that word within the uri. We would like a redirect to occur in all situations excluding when a word in included between the uri and url.

Examples:

1.) VW Models: SUVs, Sedans, Electric cars | Volkswagen => Should redirect to http://vw.com/rabbit

2.) VW Models: SUVs, Sedans, Electric cars | Volkswagen(anything else appended to uri) => Should redirect as above example to http://vw.com/rabbit

3.) http://vw.com/(something)/golf => Should NOT redirect.

Thanks!

Bryan

You’ve been presented with some if statements, here’s a switch option you can use that should do what you want.

when HTTP_REQUEST {
  switch -glob "[HTTP::host][HTTP::uri]" {
    "vw.com/golf" -
    "vw.com/golf/*" {
      HTTP::redirect "http://vw.com/rabbit"
    }
  }
}

Here’s another one that should work:

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

The downside to the second version is that this would redirect as well “http://vw.com/golfer” since it starts with “VW Models: SUVs, Sedans, Electric cars | Volkswagen”. You could change the comparison to “VW Models: SUVs, Sedans, Electric cars | Volkswagen” but that would exclude “http://vw.com/golf”. I believe the switch example above will cover both options.

-Joe

Thanks Joe for the quick response!

Much to my dismay, I realized that I posted this in the wrong forum (again…). This particular f5 is a 4.x version. Can you tell me what the rule would look like for that version or should I repost this question in the proper forum?

Sorry for confusion; I’m new to f5 and this forum.

Thanks,

Bryan

In 4.x, you don’t have the fun switch statements, so you’ll have to fall back to a plain old if statement.

if ((http_host equals "vw.com") and (http_uri starts_with "/golf")) {
   redirect to "http://vw.com/rabbit"
}

-Joe