- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FortiADC scripting Replace part of URI
We are trying to replace part of the URI in a script but we have not been able to, we have managed to rewrite it but the parameters that the URI brings us are lost.
This is the example script we are trying to make.
Url example : https://host.com/test_replace/index.html
Url final : https://host.com/services/command/index.html
when HTTP_REQUEST {
host=HTTP:header_get_value("Host")
path=HTTP:path_get()
debug("**** host is %s path is %s\n", host, path)
if path:find("/test_replace/") then
HTTP:path_set("/services/command/")
end
- Labels:
-
FortiADC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the steps from this example script:
when HTTP_REQUEST {
# Get the URI from the HTTP request.
uri = HTTP:path_get()
# Split the URI into the path and query parameters.
path, query_params = uri:split("?")
# Replace the path with the desired path.
path = path:replace("/test_replace/", "/services/command/")
# Join the path and query parameters back into a URI.
new_uri = path:join("?", query_params)
# Set the HTTP path to the new URI.
HTTP:path_set(new_uri)
}
This script will replace the path /test_replace/ with the path /services/command/ in the URI, but it will keep the query parameters intact.
