Forum Discussion
Rewrite to URL and strip part of the URI
Hi guys,
Basically i need to do this.. been testing different scenarios with HTTP_request and HTTP_RESPONSE but no luck.
- When a url comes through from this domain, we would like to rewrite as follows:
- Persona-api.domainname.com/v1/abc/…. - Rewrite to 172.17.2.7/abc/…
- Here we remove the /v1 in the path
- Persona-api.domainname.com/v2/xyz/…. – rewrite to 172.17.19.19/xyz/…
- Here we remove the /v2 in the path
- Persona-api.domainname.com/v1/abc/…. - Rewrite to 172.17.2.7/abc/…
Basically the only part of the URL that I know is persona-api.domainname.com/v1 or persona-api.domainname.com/v2
the rest after /V1 or /V2 will be dynamic and will change anytime..
How can I remove /V1 or /V2 and append the rest of the requested URL?
Any ideas are welcome..
thanks
- Kevin_StewartEmployeeTry this:
- Michael_YatesNimbostratusI would add to what Kevin Stewart told you.
- farache_28983Nimbostratusbut how will I append the rest of the URI . the piece after /V1 or /V2.. like /V2/xyz so it looks like domain./xyz instead of domain.com/v2/xyz
- santosh_81454NimbostratusHi Farache, you are trying to parse the URI. The below link is helpful.
- Kevin_StewartEmployee
The string map command replaces content within the given file, in this case the HTP::uri.
So using the supplied syntax:
{"/V1" "" "/V2" ""}
persona-api.domainname.com/v2/xyz/ becomes Persona-api.domainname.com/xyz/
To amplify Michael's comments to my original post, you can either set this in an HTTP::uri statement, which conceals the true path from the user, or simply redirect them to the new path:
if { ( [string tolower [HTTP::uri]] contains "/v1 ) or ( [string tolower [HTTP::uri]] contains "/v2" ) } {
set uri [string map -nocase {"/V1" "" "/V2" ""}]
HTTP::redirect "http://[HTTP::host]$uri"
}
- farache_28983NimbostratusFrist of all thnkas for the help
- farache_28983NimbostratusAfter looking at this , looks like the
- Michael_YatesNimbostratusHi farache,
when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] contains "/v1" ) or ( [string tolower [HTTP::uri]] contains "/v2" ) } { HTTP::uri [string map {"/v1" "" "/v2" ""} [HTTP::uri]] HTTP::redirect "http://[HTTP::host][HTTP::uri]" } }
- Michael_YatesNimbostratus
Sorry...That won't work 🙂
You could use the above to set the Variable like this: set uri [HTTP::uri [string map {"/v1" "" "/v2" ""} [HTTP::uri]]] Then you could do the following: HTTP::redirect "http://[HTTP::host]$uri" Or you could l just do this:when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] contains "/v1" ) or ( [string tolower [HTTP::uri]] contains "/v2" ) } { HTTP::redirect "http://[HTTP::host][string map {"/v1" "" "/v2" ""} [HTTP::uri]]" } }
- farache_28983NimbostratusAfter looking at this , looks like the
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