Forum Discussion
URL Rewrite
- Jun 05, 2021
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 } }
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
}
}
Hey Sanjay,
Thanks for the quick reply!
Does the replacement host "sample.com" have to be in the same LTM? In our case, it's an external address.
Regards,
Mohan Kumar
- spalandeJun 06, 2021Nacreous
It can be hosted any where. You would need to modify the iRule above to create a pool for "sample.com" and use it with pool command before return statement.
Make sure pool is reachable from the LTM.
- MohanKJun 11, 2021Altostratus
Sure! I'll do that. Thank you!
I have one more query - What if the account ID keeps changing depends on the user (&account_id=5036), is there a way to make it dynamic?
- spalandeJun 11, 2021Nacreous
In your explanation, I don't see accountID is coming in incoming URL
https://example.com/rec/widgets/item/McBq3g?=,&_br_uid_2=uid=59512300:v
from where are you retriving this account ID? I thought it's static URI you are appending with a rewrite. Did you miss anything?
- MohanKJun 11, 2021Altostratus
Yes, You're right. I was wrong, sorry about that :)
We are testing the iRule, this weekend. I'll keep you posted.
Thank You so much for all your help!
Recent Discussions
Related Content
* 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