Forum Discussion
DaveC_21078
Altostratus
Aug 27, 2009How can I chab=nge the format of a URL?
I need to be able to search for a URL similar to
http://example.com/adserver/impression/pid=123/oid=860/rand=12345/?click=http://www.publisher.com/track/ad.aspx?click=1&test=2&imp=1
and manipulte it to look like
http://example.com/ad.imp?pid=123&oid=860&rand=12345/?pclk=http://www.publisher.com/track/ad.aspx?click=1&test=2&imp=1
before passing it on. Can I do this with an iRule?
Thanks for looking.
19 Replies
Sort By
- DaveC_21078
Altostratus
I appreciate the input, but no change. I've simplified this thing as much as I can, but no joy. It is still passing the original URL. I tired - hoolio
Cirrostratus
String map won't work with variables wrapped in curly braces. So you can either use subst like Joe listed, or remove the curly braces. Also, Citizen's suggestion was to add a second HTTP request event with a priority of 501 so you could see the effect of the change once it is made. And you'll need to include a leading forward slash in the scan pattern or it won't match any URI.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::uri]" if { [HTTP::uri] contains "adserver/impression" }{ log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI check" Scan the URI looking for the pid, oid and rand values if { [scan [HTTP::uri] "/adserver/impression/pid=%d/oid=%d/rand=%d" pid oid rand] == 3 } { log local0. "[IP::client_addr]:[TCP::client_port]: Scanned three values: pid = $pid, oid = $oid, rand = $rand" HTTP::uri [string map "adserver/impression/pid=$pid/oid=$oid/rand=$rand/?click ad.imp?pid=$pid&oid=$oid&rand=$rand/?pclk" [HTTP::uri]] } } } when HTTP_REQUEST priority 501 { log local0. "[IP::client_addr]:[TCP::client_port]: 501: Updated URI: [HTTP::uri]" }
- DaveC_21078
Altostratus
Aaron, - DaveC_21078
Altostratus
Aaron, - hoolio
Cirrostratus
Hi Dave, - DaveC_21078
Altostratus
Aaron, - hoolio
Cirrostratus
The scan command is expecting a (set of) digit characters. So you could change the scan to match any character which is not a / instead:if { [scan [HTTP::uri] "/adserver/impression/pid=%s/oid=%s/rand=%s" pid oid rand] == 3 } {
if { [scan [HTTP::uri] {/adserver/impression/pid=%[^/]/oid=%[^/]/rand=%[^/]} pid oid rand] == 3 } {
- DaveC_21078
Altostratus
Aaron, - hoolio
Cirrostratus
Glad to see you got it working. Thanks to cmbhatt, Joe and Citizen as well for their suggestions.
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