URL Rewrite
we need to rewrite the incoming request to a different endpoint and add some additional parameters to the URL.
The purpose of doing this is we don't want to expose the endpoint URL and the URL parameters to the browser. Below is an example:
incoming URL:
https://example.com/rec/widgets/item/McBq3g?=,&_br_uid_2=uid=59512300:v
1. Copy the url content from the incoming url after /widgets and add it to the rewrite url https://sample.com/api/v2/widgets/
2. append 2 additional url parameters &account_id=5036&domain_key=example at the end.
Final URL should look like this:
https://sample.com/api/v2/widgets/item/McBq3g?=,&_br_uid_2=uid=59512300:v&account_id=5036&domain_key=example
Please note the URL content after /widgets will change based on type of request but the logic of rewriting should be same. that is to copy everything after /widgets and append additional url parameters.
Assuming all incoming url starts_with /rec/widgets, you can try below code
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/rec/widgets" } { HTTP::header replace "Host" "sample.com" set new_uri "/api/v2/widgets[string range [HTTP::uri] 12 end]&account_id=5036&domain_key=example" log local0. "new_uri: $new_uri" HTTP::uri $new_uri return } }