Forum Discussion

Boris_Artemyev_'s avatar
Boris_Artemyev_
Icon for Nimbostratus rankNimbostratus
Aug 08, 2007

Partial URI rewrite v 4.5

Hello,

 

I searched for a relative answer to no avail.

 

We would like to implement the following:

 

redirect http://www.mywebsite/my/very/long/dynamic/uri to http://www.mywebsite/our/very/long/dynamic/uri

 

 

"/dynamic/uri" part is challenging.

 

 

 

Any input will be highly appreciated.

 

 

 

Thank you,

 

Boris.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi,

    If you always want to redirect requests that start with "/my/very/long", you could use something like this:

    
    rule my_rule {
       if (http_uri starts_with "/my/very/long/") {
          redirect to "https://www.foorbar.com/our/very/log/%u"
       } else {
          use pool http_pool
       }
    }

    Else, if a string comparison won't work, you could use matches_regex to describe when to issue the redirect:

    
    rule my_rule {
       if (http_uri matches_regex "/my/very/long/(?:some_dynamic_string)") {
          redirect to "https://www.foorbar.com/our/very/log/%u"
       } else {
          use pool http_pool
       }
    }

    [Edits: the %u is substituted for the original URI. And it's more resource intensive to use matches_regex versus one of the string comparisons like starts_with, contains or ends_with.]

    Aaron
  • Aaron,

     

    Thanks a lot!

     

    I thought %u contains the entire URI, will my redirect become

     

    https://www.foorbar.com/our/very/long/my/very/long/teh_rest_of_the_dynamic_uri

     

    In any event, I will try it out.

     

     

    Boris.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    In the F5 lexicon, %h refers to the host and %u refers to the URI, so the example should work for you, assuming you're able to match just the requests you want redirected.

     

     

    Thanks,

     

    Aaron

     

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    I think Boris is right, that the URI will contain both the old part and the new part that way.

    He'd need to use substr or some other text manipulation to re-build the URI, maybe something like this?
    rule my_rule {
       if (tolower(http_uri) starts_with "/my/very/long/") {
          redirect to https://www.foorbar.com/our/very/long/ + substr(http_uri, 14)
       } else {
          use pool http_pool
       }
    }

    /deb