Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
ViMon
New Contributor

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

2 REPLIES 2
anignan
Staff
Staff

Hi @ViMon 

Can you try Content Rewriting under your virtual server configuration?

 

Abdel

maranoun
New Contributor

 

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.

Announcements

Select Forum Responses to become Knowledge Articles!

Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.

Labels
Top Kudoed Authors