Skip to main content
FHauser
New Member
October 6, 2022
Question

Redirect http > https using http status code 301 (instead of 302 or 307)

  • October 6, 2022
  • 2 replies
  • 4236 views

Hello,

 

how do I set the http status code when doing a rewrite or redirect to https?

The recommended methods lead to codes 302 or 307, for SEO reasons I´d need 301,

 

Best regards, Florian

2 replies

jintrah_FTNT
Staff
Staff
October 6, 2022

Hi Florian,

 

General HTTP redirect

You can redirect both HTTP requests and HTTP responses to a given location.

GENERAL_REDIRECT_DEMO:

when HTTP_REQUEST{

--can be used in both HTTP_REQUEST and HTTP_RESPONSE

--code and cookie are optional, code can be 301, 302, 303, 307, 308, if missed, 302 is used

t={}

t["code"] = 302;

t["url"] = "www.example.com"

t["cookie"] = "name=value; Expires=Wed, 09 Jun 2021 10:18:14 GMT"

HTTP:redirect_t(t);

}

 

Please see Handbook | FortiADC 7.1.0 | Fortinet Documentation Library

 

Best regards,

Jin

atakannatak
Explorer
April 27, 2024

Hi Florian,

 

You can use the script below, which serves two purposes:

 

1- It collects values from the HTTP header when a request comes to your virtual server. This is essential to avoid escaping the original request, such as the hostname and URL path.

2- It manipulates the HTTP response as you wish. In this scenario, you can manipulate your response status code however you want.

 

when HTTP_REQUEST{
Host = HTTP:header_get_value("host")
Url = HTTP:uri_get()
}
when HTTP_RESPONSE{
HTTP:status_code_set("303")
HTTP:redirect("https://%s%s", Host, Url)
}

 

However, if you use the table option, you may encounter an endless redirection situation due to a missing step in the redirection process, such as the HTTPS condition. Instead, you can change the response to a different code without further action. Solving this problem may be more complex than the approach mentioned above.

 

If my answer provided a solution for you, please mark it as such so that others can benefit. If you have found a solution, please like and accept it to make it easily accessible to others.

Thought Leadership Security Summit. Outpace New Threats with AI - enhanced defense. Tuesday, Septmeber 15, 8:30 AM - 2:30 PM PT. The Golf Club at Newcastle, WA.
Fortinet Flag the Hack. Wednesday, August 26, 9:00 AM - 5:00 PM ET, COSM, Atlanta, GA.
Virtual event | September 2026. SASE summit. The age of autonomous trust. Register here!