Forum Discussion
princess_baile1
Nimbostratus
Oct 16, 2010HTTP Rewrite/Redirect need help for newbie
Hi,
I am very new to iRules and I need help accomplishing the following:
the typical request will look something like this:
https://ixgi-commonuat.xxx.com/pms-...rvice?wsdl and I want to change the "/pms-fix" to "/pms" and retain the rest of the uri as it might change. I also will have uri's that come in with /pms already that do not have to be rewritten but will need to go to a different pool than the pms-fix traffic. I have pieced this together from some iRules we already have and reading here on the forums and I know it isn't quite right but any help is GREATLY appreciated.
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/pms"} {
log local0. "GOING TO pool_XGI_fab_PMSComponent_uat_443"
pool pool_XGI_fab_PMSComponent_uat_443
}
log local0. "PMS my uri is [HTTP::uri]"
HTTP::uri [string map {/pms-fix/ /pms/} [HTTP::uri]]}
if {uri eq "/pms/"} log local0. "uri changed from pms-fix to pms"
pool pool_XGI_fab_PMSProdfixComponent_pfix_443
here is my first question, in the string map do I need a "/" after both uri's? then does including the [HTTP::uri]]} append the remainder of the uri after the pms-fix and pms?
thank you!
Tamara
1 Reply
- The_Bhattman
Nimbostratus
Hi Tamara,
I don't believe you need to use "/" after both URLs. Remember string maps simple find and replace over one iteration.
This untested example code. It will send the traffic to the pool of it matches the first condition. If it matches the second condition it will change the URI and send the request to pool, but the client will still retain the original URI.when HTTP_REQUEST { switch -glob [HTTP::uri] { "/pmx/*" { pool pool_XGI_fab_PMXComponent_uat_443 } "/pmx-fix/*" { HTTP::uri [string map { pmx-fix pmx } [HTTP::uri]] pool pool_XGI_fab_PMXProdfixComponent_pfix_443 } } }
or
This untested code works much similar to the code above, except the client now has the new updated URI.when HTTP_REQUEST { switch -glob [HTTP::uri] { "/pmx/*" { pool pool_XGI_fab_PMXComponent_uat_443 } "/pmx-fix/*" { set newuri [string map { pmx-fix pmx } [HTTP::uri]] HTTP::redirect "http://[HTTP::host]/$newuri" } } }
I hope this helps
Bhattman
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
