Forum Discussion
lunitic_56137
Nimbostratus
Jan 29, 2013Appending content to dynamic variables a uri
Ok, I asked this before but I never received a solution for it. I have a web/app server that is returning dynamic uri variables and I need to append that.
For example:
Request comes in from the client as
http://www.company.com/companyb2c/b2c/in.do?shop=GL-L0
The web/app server returns a 302 with
http://www.company.com/companyb2c/b2c/in.do?shop=GL-L0&Product=26537
The "Product=26537" is vital and is dynamic. The number changes with each individual request for information. We need for the F5 to append this by adding "&login=true" after the number. So the full url should be formatted to be:
http://www.company.com/companyb2c/b2c/in.do?shop=GL-L0&Product=26537&login=true
I remembered there was a way to tell the parser in iRules to count past a certain point but I cannot find it in the iRule keywords.
Any ideas?
13 Replies
- What_Lies_Bene1
Cirrostratus
You could use an iRule for this in conjunction with a Stream profile to rewrite the 302 on the way out, however, perhaps it would be better/simpler to add to the URI at when the follow up request comes in? I'll have a think and get back to you. - Kevin_Stewart
Employee
While not a big advocate of regular expressions, the following may work for you. The idea, as I understand it, is to capture a 302 redirect with "&Product=" at the END of the Location header URI, and then add "&login=true".when HTTP_RESPONSE { if { [HTTP::is_redirect] } { if { [regexp {.*&[Pp]roduct=\d+$} [HTTP::header Location]] == 1 } { HTTP::header replace Location "[HTTP::header Location]&login=true" } } } - Kevin_Stewart
Employee
The editor strike again. Replace the "amp" with the ampersand symbol. - lunitic_56137
Nimbostratus
Your assumption is correct. We are going to add the code and test today.
- lunitic_56137
Nimbostratus
This did not work. I have found out some more info now. This is currently working in a Juniper DX using their keyword of append. Here is the snippet:
request_header "Host" equals "ecommerce.company.com" and url contains "/companyb2c/b2c" then replace url term "/companyb2b/b2b" and append query_string "&login=true" and route_request target_host "192.168.1.101:80"
The DX is doing a lookup, changing the b2c to b2b and then appending &login=true to the end of the query string.
I have a pretty ugly iRule that is doing a switch for all of the uri changes that need to be made but the append part doesn't work. In the uri checks, it looks for b2c and redirect rewrites to b2b by using the standard HTTP::redirect and giving it the full path. But now there is a server component to this all. When you get redirected to the b2b link and select a product, the server adds the "&Product=76543". This number is dynamic so I dont know what it is and I cant figure out how to also append the "&login=true" to it as well. - Kevin_Stewart
Employee
How did the iRule not work? It is designed to find the "&Product=" string at the END of the URI in the Location header of a 30x redirect.
Your Juniper DX rule essentially says to change the URI in the request message (going to the server), while you originally stated that the URI was in the 302 redirect message (going to the client). - lunitic_56137
Nimbostratus
That was my understanding. I am trying to add your code to a different part of the iRule to see if I can get it to fire somewhere else. It seems that it is not a 302 from the server. The DX is making the changes all in one fell swoop. - lunitic_56137
Nimbostratus
Ok, I had to move the code into the switch statement and it worked like a champ. Thank you very much. - lunitic_56137
Nimbostratus
Any idea of the v11 version of this? - lunitic_56137
Nimbostratus
Any idea of the v11 version of this?
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