Skip to main content
anova
Staff
Staff
March 23, 2026

Technical Tip: Configuring HTTP redirect with 301 return code instead of 302 on FortiADC

  • March 23, 2026
  • 0 replies
  • 180 views
Description This article describes how to configure a Lua script on FortiADC to achieve an HTTP redirect with a 301 return code. The user requires assistance with editing the Lua script to redirect HTTP requests to a specific URL with a 301 return code.
Scope FortiADC.
Solution

To configure an HTTP redirect with a 301 return code on FortiADC, follow these steps:

Go to Server Load Balance -> Scripting, make sure the tab is under 'HTTP', select 'Create New'. 


In the script, add the following Lua code:

 

when HTTP_REQUEST{ host = HTTP:header_get_value("host") path = HTTP:path_get() t={} t["code"] = 301; t["url"] = string.format("https://%s%s", host, path); HTTP:redirect_t(t); }


Make sure to configure one virtual server (VS) for the HTTP service, where the redirection script is specified, and another VS with HTTPS for application access. Note: It is essential to split up the HTTP/HTTPS services into two separate instances to avoid excessive redirects.

 

301 redirect LUA script VS example.png


Verify that the redirect is working as expected by checking the HTTP response code.

 

Related article: 

Technical Tip: Configuring HTTP Redirect with 301 Return Code instead of 302 on FortiADC