Forum Discussion

brownie6969_121's avatar
brownie6969_121
Icon for Nimbostratus rankNimbostratus
May 31, 2012

redirect irule

our old application url that pointed to the F5 vip was mybicrt.company.com. The new code is mybicrt.company.com/analytics. i created the following that achieves that part of it

 

when HTTP_REQUEST {

 

if { [HTTP::path] equals "/" } {

 

HTTP::redirect "/analytics/"

 

log local0. "redirect"

 

}

 

}

 

now the problem is that users have links to dashboards saved that look like this

 

https://mybicrt.company.com/saw.dll?Dashboard&PortlPath/shared/Executive/_portal/Executive

 

 

and we need them to redirect to

 

 

https://mybicrt.company.com/analytics/saw.dll?Dashboard&PortlPath/shared/Executive/_portal/Executive

 

 

basically the irule we have setup stops at analytics and I need a way to add /analytics after mybicrt.compan.com but keep the rest of the url there. Also there are a ton of dashboard links that are all different.

 

 

is this possible.

 

 

Thanks

 

Andrew

 

  • This iRule is assuming that all requests should begin with /analytics If the images are stored in a location other than /analytics you will have to account for that in the iRule. Are all of the images contained within a single location? If so, please provide an example of one of the image locations.
  • OK. Try this...

     

     

    I shouldn't have built upon what had been provided. The first "/" event needs to be handled....the "/" - will pass it to the next event which is supposed to inject the "/analytics"...so either remove it or point it to where it should be redirected to.

     

     

    For some reason it wasn't capturing the URI::basename, so rather than building another switch event I just added the trailing "*/saw.dll*" to make it absolute....this could cause problems if anything else on the Virtual Server that uses "/saw.dll" and doesn't need to go to the "/analytics" directory.

     

     

    This will capture it anywhere in the URL and inject the "/analytics"....it will also (in the First iRule) log the Original HTTP::uri. Then add a second iRule and put the code below in it...then make sure that this iRule is BELOW the first iRule when applied to the Virtual Server (you could use iRule Priorities, but I'm sticking to the topic). This will log the modified HTTP::uri value in the LTM log so that you can verifiy that it is working properly.

     

     

    
    First iRule:
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::path]] {
    "/" { HTTP::respond 301 Location "http://www.google.com" }
    "*/saw.dll*" {
    HTTP::uri "/analytics[HTTP::uri]"
    log local0. "Saw Event:  URI - [HTTP::uri]"
    }
    }
    }
    
    Second iRule for proof that the first is working:
     when HTTP_REQUEST {
        log local0. "Second iRule HTTP::uri Value:  [HTTP::uri]"
    }
    

     

     

    If it works properly you should see this in your LTM Log:

     

    Jun 1 16:31:46 local/tmm1 info tmm1[30732]: Rule Z.iRule.Development : Saw Event: URI - /saw.dll?Dashboard&PortlPath/shared/Executive/_portal/Executive

     

    Jun 1 16:31:46 local/tmm1 info tmm1[30732]: Rule Z.iRule.Development.2 : Second iRule HTTP::uri Value: /analytics/saw.dll?Dashboard&PortlPath/shared/Executive/_portal/Executive

     

     

    If your curious about the second iRule for verification you can read this thread: Log Not Showing Modified URI

     

     

    Hope this helps and fixes it 🙂

     

  • it took awhile estjohn but it started working. We test a ton of links and we are good to go.

     

    Thank you so much everyone for all of the help. I learned a ton from all of you and fixed the issue.

     

     

    Andrew
  • Hey estjohn,

     

    so that worked but these three exceptions need to be added to the rule

     

    /em, /console, or /mybi

     

     

    basically we need to keep the irule that you gave me so everything goes to /analytics except the following

     

    https://mybicrt11g.company.com/em

     

    https://mybicrt11g.company.com/console

     

    https://mybicrt11g.company.com/mybi/images/siebel.gif

     

     

    Is there a way to add those exceptions to

     

    when HTTP_REQUEST {

     

    if { !([HTTP::path] starts_with "/analytics") } {

     

    HTTP::redirect "/analytics[HTTP::uri]"

     

    }

     

    }

     

     

    Thanks

     

    Andrew