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
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
I recently came across an interesting topic about redirecting HTTP to HTTPS using a 301 status code instead of 302. I found that using 301 code is more SEO friendly and helps maintain link mass. Care should be taken to ensure that your server configuration is set up correctly. Check out this helpful guide I found on the https://admiral-studios.com/ website - it contains detailed information about optimizing redirects. You can also always consult the experienced professionals from this company. I hope this helps you in your transition to HTTPS! Cheers!
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.
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.