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

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

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 2
jintrah_FTNT
Staff
Staff

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
New Contributor III

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.

Atakan Atak
Atakan Atak
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