Forum Discussion
Getting a forwarding port from a URI
This is kind of a revisit. I asked this question and got some help a few months back but now there is more needed from the developer (isn't that always the way?)
SO I wrote the below Irule with a lot of help from you guys. The problem I am having now is that "sometimes" the uri is only the port. So www.blablabla.com/1234/ works with the script below, but I can't figure out how to make it work if I remove the second slash. So www.blablabla.com/1234 doesn't work. I need it to be able to work with no second slash as well as a few slashes. In other words I need www.blablabla.com/1234 to work as well as www.blablabla.com/1234/more/crap/after/here. Can anyone see how to make both work?
when HTTP_REQUEST { set newuri [findstr [HTTP::uri] "/" 5] log local0. "Original request is: [HTTP::host][HTTP::uri]" log local0. "New URI is: $newuri" set newport [findstr [HTTP::uri] "/" 1 4] HTTP::uri "$newuri" log local0. "New Port is: $newport" HTTP::header replace Host "[HTTP::host]:$newport"
if { $newport ne "" } { Use the relevant Pool pool mule_pool_$newport } else { log local0. "Newport Variable was empty" } }
As always Thank you very much for your help! Joe
3 Replies
- sundogbrew
Altocumulus
PS, how do you post the code without it turning into a sentence?
- Kevin_Stewart
Employee
Can I assume that if there's nothing after the port number then the newuri variable is empty? If so, then a quick check and replace function should do the trick:
if { not ( $newuri starts_with "/" ) } { set newuri "/${newuri}" }So it might look something like this:
when HTTP_REQUEST { set newuri [findstr [HTTP::uri] "/" 5] if { not ( $newuri starts_with "/" ) } { set newuri "/${newuri}" } log local0. "Original request is: [HTTP::host][HTTP::uri]" log local0. "New URI is: $newuri" set newport [findstr [HTTP::uri] "/" 1 4] HTTP::uri "$newuri" log local0. "New Port is: $newport" HTTP::header replace Host "[HTTP::host]:$newport" if { $newport ne "" } { Use the relevant Pool pool mule_pool_$newport } else { log local0. "Newport Variable was empty" } } - sundogbrew
Altocumulus
That did the trick! Thank you very much as always! Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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