Forum Discussion

BigIP_Support_9's avatar
BigIP_Support_9
Icon for Nimbostratus rankNimbostratus
Feb 23, 2006

Change URI without redirect

I want to change the user URI as below:

 

 

http://www.abc.com/demo -> http://www.abc.com/demo1

 

 

Here is my code:

 

 

if (http_uri == "/demo") {
   redirect to "http://" + http_host + "/demo1/"
}
else {
   if (http_uri matches_regex "/demo/") {
      redirect to "http://" + http_host + "/demo1/" + substr(http_uri, 6, 1000)
   }
   else {
      use pool demo-pool
   }
}

 

 

It works but it requires too many redirect. Clients are required to use new conenction after redirect according

 

to RFC 2616.

 

In fact I just want to change demo to demo1. Can I change the URI and forward to demo-pool pool within a single "if" clause? I don't want to redirect and client go back again and falls to the last "if" clause.

5 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    It looks like you just need to work on your logic a little. Your second if clause would grab a lot of the same URIs as the first one, unless there's been something added to the "demo" in the uri.

     

     

    I'd recommend changing the logic of the second if clause to be a little more specific in looking for a uri that has demo as well as something else, so that users won't end up getting redirected twice.

     

     

    As it stands right now, the user comes in with a URI of "demo", gets redirected to "demo1" then gets redirected again because that still matches the regex in the second if clause.

     

     

    -Colin
  • The first if-clause is to capture http://www.abc.com/demo

     

    The secondd if-clause is to capture http://www.abc.com/demo/ or http://www.abc.com/demo/xx/yy.html etc

     

     

    I will get redirect one time only no matter which case it is. However we don't want that redirect because it is redirect back to bigip itself. It would be much more efficient to change the URI and forward to a pool immediately, rather than get back the redirect to client and client initiate a new request to match the last else-clause.
  • I searched and see that in v9.x iRules, we can do below, so we don't need to use REDIRECT to just to change the URI but still forward to same FQDN, same server pool

    
    if (http::uri equals "/demo") {
       HTTP::uri "http://" + http_host + "/demo1/"
       pool demo-pool
    }
    else {
       if (http::uri contains "/demo/") {
          HTTP::uri "http://" + http_host + "/demo1/" + substr(http_uri, 6, 1000)
          pool demo-pool
       }
       else {
          pool demo-pool
       }
    }

    How can I do above in v4.x?
  • Martin_Machacek's avatar
    Martin_Machacek
    Historic F5 Account
    There is no way how to achieve what you want in v4.x. v9.x iRules are much more powerful.
  • I needed the same type of iRule and this worked for me with no redirects.

    when HTTP_REQUEST {
      if { [string tolower [HTTP::path]] starts_with "/demo/" } {
          HTTP::path [string map {"/demo/" "/demo1/"} [HTTP::path]]
      }
      else{
          pool demo-pool
      }
    }