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
...
hoolio
Cirrostratus
Aug 27, 2009Hi,
You can rewrite the URI using HTTP::uri or HTTP::path. You can retrieve the URI and path with these commands as well. You can use HTTP::query to get the query string value. You can use URI::query [HTTP::uri] param_name to get the value of a specific parameter in the query string.
Here is an untested example which should give you some ideas on how to do this. I made some assumptions about when you would want to rewrite the URI and which fields you would want to take from the original URI.
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::uri]"
Check the requested path?
if {[HTTP::path] eq "/adserver/impression/pid=123/oid=860/rand=12345/"}{
Rewrite the URI to /ad.imp? then take the third through fifth fiels in the path
and append the query string parameter pclk with the value of click from the original query string
HTTP::uri "/ad.imp?[URI::path [HTTP::uri] 3 5]?pclk=[URI::query [HTTP::uri] click]"
log local0. "[IP::client_addr]:[TCP::client_port]: Rewrote URI to: /ad.imp?[URI::path [HTTP::uri] 3 5]?pclk=[URI::query [HTTP::uri] click]"
}
}
when HTTP_REQUEST priority 501 {
This event is just used for debug logging of the values that are cached in the default priority 500 HTTP_REQUEST event above
You can comment out or remove this event when you're done testing
log local0. "[IP::client_addr]:[TCP::client_port]: Actual updated URI: [HTTP::uri]"
}
Aaron
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