It is very often desired to have only one form of the URL (with or without www) and sometimes to enforce all traffic to be https.
“SEO Redirect” action solves these two problems in a simple rule setup and ensures the usage of a single redirect from any original format to your target URL type. Furthermore, these redirects are emitted directly by the HAproxy entry point, which avoids loading a backend web service with this processing.
Since most of the times these redirects need to happen on all URLs, you can use a generic condition that would cover all cases such as “Path” begins with “/”.
The target URL format is defined by the scheme redirect type (“scheme_http”, “scheme_https” or “leave_unchanged”) and by the “www redirect” type (“With www”, “Without www” or “Leave unchanged”).
The “redirect type” filed specifies the redirect code to be used in the response. Available codes are:
- 301 – Permanent redirect
- 302 – Temporary redirect
- 307 – Temporary Redirect and keep method
- 308 – Permanent Redirect and keep method
307 and 308 response codes are a bit lesser known codes and they function as their 301 and 302 counterparts but additionally instruct the browsers to keep the same method and parameters (i.e. POST method and parameters) when calling the target URL.
If you do not require a “www redirect” type (specified with “Leave unchanged”) and you only need a http/https redirect, a small processing optimization can be achieved by specified a condition for the initial schema. For example, when redirecting to https you can specify a “schema” condition “http” and vice versa for redirects to http, you can specify a “schema” condition “https”. This optimizes a bit rule placement and evaluation in HAproxy and avoids unnecessary processing.