Fortinet white logo
Fortinet white logo

Script Reference Guide

Rewrite the HTTP response Location header

Rewrite the HTTP response Location header

You can use the content rewriting feature to rewrite the HTTP response Location header. If you are more comfortable using Lua string substitution, you can write a script to get the results you want. The following example rewrites the HTTP response Location header.

Rewrite the HTTP body in the response:
when RULE_INIT {
        debug("rewrite the HTTP Host header and path in a HTTP request \n")
}
 
when HTTP_REQUEST{
       host = HTTP:header_get_value("Host")
       path = HTTP:path_get() 
       if host:lower():find("myold.hostname.com") then
              debug("found myold.hostname.com in Host %s \n", host)
              HTTP:header_replace("Host", "mynew.hostname.com")
              HTTP:path_set("/other.html")
       end
}

Rewrite the HTTP response Location header

Rewrite the HTTP response Location header

You can use the content rewriting feature to rewrite the HTTP response Location header. If you are more comfortable using Lua string substitution, you can write a script to get the results you want. The following example rewrites the HTTP response Location header.

Rewrite the HTTP body in the response:
when RULE_INIT {
        debug("rewrite the HTTP Host header and path in a HTTP request \n")
}
 
when HTTP_REQUEST{
       host = HTTP:header_get_value("Host")
       path = HTTP:path_get() 
       if host:lower():find("myold.hostname.com") then
              debug("found myold.hostname.com in Host %s \n", host)
              HTTP:header_replace("Host", "mynew.hostname.com")
              HTTP:path_set("/other.html")
       end
}