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
Nominating a forum post submits a request to create a new Knowledge Article based on the forum post topic. Please ensure your nomination includes a solution within the reply.
Hi Florian,
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
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.
Select Forum Responses to become Knowledge Articles!
Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.
User | Count |
---|---|
1692 | |
1087 | |
752 | |
446 | |
228 |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.