Forum Discussion
Remove /api from uri and forward remaining uri
Hi F5 gurus, I have a real quick question, I am looking for a possible syntax to strip out the /api from all the URIs that hit my VIP and send the remaining URL without changes. Is that possible? I tried some rules that included redirects but customer doesn't want a hard coded redirect.
I really appreciate if somebody can provide a code example so I can test it out.
Certainly it is possible to remap URI sent to backend server. Some example from https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx.
Code Make uri path start with /prefix if it doesn't already when HTTP_REQUEST { if { not ([HTTP::uri] starts_with "/prefix") } { HTTP::uri /prefix[HTTP::uri] } }
- Lee_Sutcliffe
Nacreous
If the user requesting "/api/index/folder" but you want the user to see /index/folder you could use a redirect:
when HTTP_REQUEST { if {[HTTP::uri] starts_with "/api"} { set trim /[getfield [HTTP::uri] "/" 2] set endUri [string range [HTTP::uri] [string length $trim] end] HTTP::redirect http://[HTTP::host]$endUri } }
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