Skip to main content
Zdenek1
Explorer
March 25, 2024
Question

Scripting - URL path replacement

  • March 25, 2024
  • 2 replies
  • 1442 views

I have this string:

 

when HTTP_REQUEST{     path = HTTP:path_get()          debug("Path rewrite starts for Path %s ", path)      -- replace path which is /prefix/something/* so only /something/* stays in the path     HTTP:path_set("%s", path:gsub("/prefix", ""))  }

 

How to achieve the removal of the prefix? This script does not work. Also I don't see debug messages in the logs even though Scripting logging is enabled.

 

Thanks

2 replies

CatInHat
Explorer
March 25, 2024

Try running the regex directly to make sure it removes the prefix correctly. For example, try running the following code in your environment:
local path = "/prefix/something/example"
local modified_path = path:gsub("/prefix", ")
print(modified_path)

Zdenek1
Zdenek1Author
Explorer
March 26, 2024

Hi, I guess missing " in your args for gsub is a typo, right?

Anyway I have added the log using print as you suggested, I still don't see anything in Script logs, but I have "Script Category" enabled in "Local log" settings.

How it is with logging at FortiADC, what else is needed to get the logs visible, do you know? Thanks

Zdenek1
Zdenek1Author
Explorer
March 27, 2024

So after all it is "log" command to log stuff in Script, it is not "debug" nor "print".