Forum Discussion
paulhaskew_7063
Nimbostratus
Jun 24, 2009Rewrite portion of URI?
Hi everyone. First off this forum/website has been invaluable for finding information and answering my questions for quite some time. Wonderful!
So to my question, I have a particular site that we are accessing via http://sub.domain.com/culture/someservice/partners/?qs=*.
The problem I have is that the actual site lives on on http://sub.domain.com/culture/someservice.svc/partners/?qs=*.
The devs would like the flexability to be able to rewrite a portion of the URI dynamically when its requested from multiple cultures. The culture strings could be, en-US, en-GB, nl-NL, etc etc.
Here is the current iRule I wrote to simple just redirect the traffic based on what is contained within the URI, but how to setup the dynamic replace escapes me.
when HTTP_REQUEST {
if {([string tolower [HTTP::uri]] contains "someservice") } {
pool my_secondary_pool
} else {
pool my_first_pool
}
log local0. "Request: [HTTP::uri]"
}
I have looked at the stream command and tried HTTP::header but alas I admit defeat.
Any help would be greatly appricated.
6 Replies
- L4L7_53191
Nimbostratus
To make sure I understand this: The BigIP will see a header named "URI" with a value like 'en-US' or 'en-GB', or with a value like 'syndicate.en-GB'?
Are you looking to redirect to the appropriate service, or are you looking to dynamically change the URI as it the request is passed back to the server? Either is fine, I'm just trying to understand the flows and behaviors...
Sorry if I am confused.
-Matt - paulhaskew_7063
Nimbostratus
Matt,
Thanks for the reply, and no worries on the confusion.
What we are trying to do is dynamically replace the word someservice with someservice.svc in the URI string. The reason for the replace on the load balancer is so that its transparent to the end user and what is shown in the browser never changes. - L4L7_53191
Nimbostratus
Gotcha. So how do I know what service a user is coming from? Are you using the Accept-Language header to determine the ultimate service destination?
-Matt - paulhaskew_7063
Nimbostratus
Not entirely sure how the devs are doing the culture work, that portion is coded in C and using II6. The culture request could change at any time really. Is there a way to deal with that start and ending portion of the URI with a wild card? - hoolio
Cirrostratus
What we are trying to do is dynamically replace the word someservice with someservice.svc in the URI string.
To literally do that you can use string map:when HTTP_REQUEST { Replace someservice with someservice.svc in the path of the request. Leave everything else in the path intact. HTTP::path [string map -nocase {someservice someservice.svc} [HTTP::path]] log local0. "[IP::client_addr]:[TCP::client_port]: Rewrote [HTTP::path] to\ [string map -nocase {someservice someservice.svc} [HTTP::path]]" }
If you don't expect the someservice string to be in a majority of requests, you could first check to see if the path contains someservice before trying to rewrite it with HTTP::path.
Aaron - paulhaskew_7063
Nimbostratus
rock on, thanks man, I will give this a go. :D
/EDIT
Works fantastic, thank you very much, I wrapped it into my existing rule so the if statement applies. You guys ROCK!
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