Forum Discussion
URI rewrite assistance
Hello all,
I am looking to hopefully do a simple irule uri rewrite, but this one is stumping me. I have a request to rewrite a uri from: http://somehost.com/reports/api/ to http://somehost.com/reports/api/v1/. Simple enough, and I got that to work with the irule below. But, they have several uri's that start with something different, so instead of reports it could be /admin/, /card/, /fee/ etc... I prefer the irule to be dynamic if possible and not have to list each directory out, and if possible use an asterisks or something for matching on */api/ and rewrite to */api/vi/. Hopefully this makes sense.
Those would look like: http://somehost.com/admin/api/ http://somehost.com/card/api/ http://somehost.com/fee/api/
So, is there a way to write an irule and use an asterrisks
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/reports/api/" } {
set uri [string map -nocase {"/reports/api/" "/reports/api/v1/"} [HTTP::uri]]
HTTP::uri $uri
}
}
Any help is appreciated.
- P_K
Altostratus
Try this.. should work
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] ends_with "/api/" }
If your VIP is on port 443, change HTTP::redirect https://[HTTP::host][HTTP::uri]v1/
- GioG
Nimbostratus
None of that worked, but the "contains" lead me downt he correct path. Here is the final irule.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/api/" } { set uri [string map -nocase {"/api/" "/api/v1/"} [HTTP::uri]] HTTP::uri $uri } }
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