Forum Discussion
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%20departmentWe 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%20departmentI 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.
The fragment portion of the URL is a client-only feature that the browser uses to link to an anchor on the page. The value including, and past, the hash character is not passed by the browser to the server so the iRule won't see it.
Source:
You can find the logs in /var/log/ltm
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com