Forum Discussion

Nifford's avatar
Nifford
Icon for Nimbostratus rankNimbostratus
Mar 03, 2017

Dynamic Redirect iRule URI Variable

I am trying to perform a dynamic redirect based a portion of the URI.

Here is what I'm trying to accomplish:

Ex. Request: http://search.company.com/Pages/results.aspx/k=accounting%20department

Ex. Redirect: https://www.company.com/search/?&query=accounting%20department

We are using a separate virtual server for search.company.com, so I created the following iRule and associated it with the virtual server:

when HTTP_REQUEST {
   set uri [HTTP::uri]
   if { $uri starts_with "/Pages/results.aspx/k=" } {
      log local0. "Original URI: $uri" 
      HTTP::uri [string range [HTTP::uri] 23 end]
      log local0. "Search Query: [HTTP::uri]"
      HTTP::uri /search/?&query=[HTTP::uri]
      log local0. "New URI: [HTTP::uri]"
      HTTP::redirect "https://www.company.com[HTTP::uri]"
   }
   elseif { $uri starts_with "/Pages/results.aspx" } {
      HTTP::redirect "https://www.company.com/search"
   }
}

Unfortunately, this is not having the desired result. Here is the behavior I am seeing:

Request: http://search.company.com/Pages/results.aspx/k=accounting%20department

Redirect: https://www.company.com/search/?&query=k=accounting%20department

I attempted to find the log entries for this iRule, but was unable to.

Can anyone offer any guidance of how I can accomplish this? Or at the very least, where I need to look for log entries and what log level needs to be enabled for which types?

Also, please feel free to correct anything you find in the iRule, whether or not it is directly contributing to the issue. I'm still learning, and trying to figure out the best way to accomplish things, as well as general best practices.

Thank you for your time and input.