Forum Discussion

Dennis_Jalbert's avatar
Dennis_Jalbert
Icon for Nimbostratus rankNimbostratus
Sep 24, 2011

Complex Redirect

I’m trying to create a redirect which changes the FQDN, keeps part of the URL static, and preserves the remaining part of the URI. That static part is going to be different on each side of the redirect though. Here is an example: hosta.site.com/blah1/blah2/blah3/* should redirect to hostb.site.com/something1/something2/something3/* where * could be anything that needs to be copied over. It seems like I need to assign the wildcard part to a variable and then just use that in the redirect statement, but I’m not sure how to do that. I haven't done anything this complex before and I wasn't able to find anything like this by searching for forums. Thanks in advance!

4 Replies

  • Hi Dennis,

     

    It's a bid hard to suggest without diving into your example. However the first step I think is outline some commands that might be helpful

     

     

    For example URI:: command would help you parse the path or query or port

     

    http://devcentral.f5.com/wiki/iRules.URI.ashx

     

     

    I hope this is a good start

     

     

    Bhattman

     

  • Patrick_Chang_7's avatar
    Patrick_Chang_7
    Historic F5 Account
    The split command will allow you to separate the URI into sections (based upon the separator - "/" seems the most logical one to use here).
  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Coming from a perl perspective, I'd probably use a regex myself... But timings may force another approach. Long uri strings with many /'s in them may make using split unweildy.

     

     

    Testing would show the best approach from a myriad of possibilities.

     

     

    H
  • Hey guys,

     

     

    Thanks for the help! I was able to do what I needed by using the HTTP::path and the string map command to change the static part of the URI. Then I used the HTTP::redirect command to change the hostname.

     

     

    Sorry for not posting sooner, but the forums don't work when I'm on the company network and I kept forgetting to update this when I get home.