Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

URL redirect policy with wildcard

I realize there are straightforward ways to do this with an iRule, but trying to do this with a simple LTM policy.

what we want is:

group1.domain.com/directory1 redirects to cloud1.domain.com/directory1

however I have unknown/infinite directory options, so this needs to be a wildcard

I see how to simply make group1.domain.com redirect to cloud1.domain.com, but I need it to be group1.domain.com/*, and carry that directory over.

Anyway to not irule this one? :)

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Yes, you can do this with a local traffic policy. Here's a screenshot of what the policy looks like:

Image Text

It's rather difficult to see inline in this article. You can save it to your desktop to see it better. Here's the basic code... the log action is not required:

Conditions:

  1. HTTP Host full string is 'group1.domain.com' at request time

Actions:

  1. Redirect to location 'tcl:https://cloud1.domain.com[HTTP::uri]' at request time.
  2. Log message 'tcl:Redirecting https://group1.domain.com[HTTP::uri] to https://cloud1.domain.com[HTTP::uri]' at request time

I made the assumption that this was an HTTPS virtual server. If not, just change the https to http.

Finally, here's the policy's configuration from TMSH:

ltm policy redirect_group1_to_cloud1 {
    controls { forwarding }
    last-modified 2018-11-26:10:46:34
    requires { http }
    rules {
        redirect_group1_to_cloud1 {
            actions {
                0 {
                    http-reply
                    redirect
                    location tcl:https://cloud1.domain.com[HTTP::uri]
                }
                1 {
                    log
                    write
                    facility local0
                    message "tcl:Redirecting https://group1.domain.com[HTTP::uri] to https://cloud1.domain.com[HTTP::uri]"
                    priority info
                }
            }
            conditions {
                0 {
                    http-host
                    values { group1.domain.com }
                }
            }
        }
    }
    status published
    strategy first-match
}
0
Comments on this Answer
Comment made 1 week ago by _maxmau5_ 1

That did it! I didn't realize a TCL would fit in that line but it works exactly as needed, thanks.

0
Comment made 1 week ago by crodriguez

Yes, it's a nice feature that was added fairly recently. Really ups the power and usability of Local Traffic Policies. Plus you get better performance than with an iRule.

0
Comment made 4 days ago by The Y 210

Is it possible in this case to add an HTTP Status code like a 3XX to the response?

0
Comment made 4 days ago by crodriguez

Yes, it is. On the rule's redirect action, you'll find an Options field in which you can specify the HTTP response code.

For example:

Image Text

0
Comment made 4 days ago by The Y 210

I appreciate that. Thank you

0
Comment made 3 days ago by _maxmau5_ 1

While this worked perfectly, the requirements changed :)

I also now need to strip a particular variable from the URI, because god forbid users update documentation...

anyway, it now needs to read like this:

group1.domain.com/directory1 redirects to cloud1.domain.com/directory1

BUT, group1.domain.com/directory1/default.apx needs to redirect to cloud1.domain.com/directory1. Keeping default.apx breaks the redirection.

So I need to keep the first URI path, but drop 'default.apx', but only that variable if its there.

now am I stuck with irule? Or is there a way to modify the request and then processes the redirect in the policy?

0
Comment made 3 days ago by crodriguez

Do you always need to drop the filename portion of the request or just if it's default.apx? How about any query string portion of the request? Is a query string ever provided?

0
Comment made 3 days ago by _maxmau5_ 1

Only that single string should be expected to be dropped, anything else is kept and appended like the original setup you showed. I guess it used to work on our sharepoint site but now it takes people to the root when its included (so cloud1.domain/sites/finance/projects/default.apx redirects to cloud1.domain/sites/finance on the cloud provider's logic). So there are links out there that have it still.

0
Comment made 3 days ago by crodriguez

Then you can change the redirect location to something like this:

Redirect to location 'tcl:https://cloud1.domain.com[string map { "/default.apx" "/" } [string tolower [HTTP::uri]]]' at request time
0