HTTP Redirect

Basic Concept

HTTP redirect is a feature provided by ALB. It will directly return a 30x HTTP code for the request that matches the rule. The Location header will be used to instruct the client to redirect to the new URL.

ALB supports redirect configuration at the port and rule levels.

CRD

redirect:
  properties:
    code:
      type: integer
    host:
      type: string
    port:
      type: integer
    prefix_match:
      type: string
    replace_prefix:
      type: string
    scheme:
      type: string
    url:
      type: string
  type: object

Redirect could be configured on:

  • Frontend: .spec.config.redirect
  • Rule: .spec.config.redirect

Ingress Annotation

AnnotationDescription
nginx.ingress.kubernetes.io/permanent-redirectCorresponds to URL in CR, will set code to 301 by default
nginx.ingress.kubernetes.io/permanent-redirect-codeCorresponds to code in CR
nginx.ingress.kubernetes.io/temporal-redirectCorresponds to URL in CR, will set code to 302 by default
nginx.ingress.kubernetes.io/temporal-redirect-codeCorresponds to code in CR
nginx.ingress.kubernetes.io/ssl-redirectCorresponds to scheme in CR, will set scheme to HTTPS by default
nginx.ingress.kubernetes.io/force-ssl-redirectCorresponds to scheme in CR, will set scheme to HTTPS by default

SSL-Redirect

  1. SSL-redirect and force-ssl-redirect differ in that SSL-redirect only takes effect when the ingress has a certificate for the corresponding domain, while force-ssl-redirect takes effect regardless of whether there is a certificate.
  2. For HTTPS ports, if only SSL-redirect is configured, the redirect will not be set.

Port Level Redirect

When redirect is configured at the port level, all requests to this port will be redirected according to the redirect configuration.

Rule Level Redirect

When redirect is configured at the rule level, the request matching this rule will be redirected according to the redirect configuration.