Forum Discussion

Hiro_Castro_341's avatar
Hiro_Castro_341
Icon for Nimbostratus rankNimbostratus
Nov 23, 2017

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.

 

  • 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
        } 
     }