Forum Discussion
Is this valid? Http:query
api.mycompany.com/compute/v1/whatever-gets-typed-next
to
api.mycompany.com/compute/v2/whatever-gets-typed-next
The key is that the 'whetever-gets-typed-next' needs to stay in place when the redirect is issued.
So i have done this:
/compute/v1/*" {
HTTP::respond 301 Location "https://api.mycompany.com/compute/v2/[HTTP::query]"
It seems to work, testing shows that it is ok.... but just wanted to confirm this is the correct way to do the redirect
- hoolioCirrostratusHere's a breakdown of the common URI commands:
- Ryan_Paras_7933Nimbostratus
I have a feeling you were already attempting to handle this within a switch statement, leading me to be believe you want to be able to handle multiple uris....
may I suggest something like the following:
rule replace_uri {
when HTTP_REQUEST {
switch -regexp "[string tolower [HTTP::uri]]" {
"^/compute/v1/" {
set replace_uri [string replace [HTTP::uri] 0 11 "/compute/v2/"]
HTTP::respond 301 Location "http://[HTTP::host]$replace_uri"
}
"^/some/other/uri/you/want/to/replace/" {
set replace_uri [string replace [HTTP::uri] 0 35 "/some/other/target/"]
HTTP::respond 301 Location "http://[HTTP::host]$replace_uri"
}
}
}
}
this "switches" against the uri to look for a "/compute/v1/" at the beginning of the uri. if it finds it, it creates a variable, replace_uri, where it replaces string indices 0 to 11 (that is "/compute/v1/") with "/compute/v2/". It then redirects to http://[HTTP::host]$replace_uri
the second conditional "switch" looks for "/some/other/uri/you/want/to/replace/" at the beginning of the uri. if it finds it, it creates a variable, replace_uri, where it replaces string indices 0 35 (that is "/some/other/uri/you/want/to/replace") with "/some/other/target/". It then redirects to http://[HTTP::host]$replace_uri
if neither conditional is met in the switch statement, then nothing happens
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