<p>I am trying to redirect a <code>non www</code> request to <code>www</code>. I checked the annotations here <a href="https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/" rel="noreferrer">https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/</a> but could not find specific to non www to www redirect.</p>

<p>I already have a <code>http</code> to <code>https</code> redirect set and it's working.</p>

<p>below is my ingress resource manifest file.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: eks-learning-ingress
  namespace: production
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/certificate-arn: ard878ef678df
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
  labels:
    app: eks-learning-ingress
spec:
  rules:
  - host: www.myhost.in
    http:
      paths:
        - path: /*
          backend:
            serviceName: ssl-redirect
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: eks-learning-service
            servicePort: 80
</code></pre>

<p>Any help in this would be great. Thanks.</p>

<p>There are 2 ways of doing non-www to www redirections, 1. using <code>alb.ingress.kubernetes.io/actions</code>, 2. <code>alb.ingress.kubernetes.io/conditions</code>.</p>
<hr />
<h2><a href="https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/#actions" rel="nofollow noreferrer">alb.ingress.kubernetes.io/actions</a></h2>
<blockquote>
<p>alb.ingress.kubernetes.io/actions.${action-name} Provides a method for
configuring custom actions on a listener, such as for Redirect
Actions.</p>
<p>The action-name in the annotation must match the serviceName in the
ingress rules, and servicePort must be use-annotation.</p>
</blockquote>
<p>We need to have one more annotation, which tells ALB how to configure redirection:</p>
<pre><code>alb.ingress.kubernetes.io/actions.redirect-to-www: &gt;
    {&quot;Type&quot;:&quot;redirect&quot;,&quot;RedirectConfig&quot;:{&quot;Host&quot;:&quot;www.myhost.in&quot;,&quot;Port&quot;:&quot;443&quot;,&quot;Protocol&quot;:&quot;HTTPS&quot;,&quot;StatusCode&quot;:&quot;HTTP_302&quot;}}
</code></pre>
<p>And one more host rule to catch your request domain <code>myhost.in</code> and redirect to <code>www.myhost.in</code></p>
<pre><code>- host: myhost.in
  http:
    paths:
      - path: /*
        backend:
          serviceName: redirect-to-www
          servicePort: use-annotation
</code></pre>
<h2><a href="https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/#conditions" rel="nofollow noreferrer">alb.ingress.kubernetes.io/conditions</a></h2>
<blockquote>
<p>alb.ingress.kubernetes.io/conditions.${conditions-name} Provides a
method for specifying routing conditions in addition to original
host/path condition on Ingress spec.</p>
<p>The conditions-name in the annotation must match the serviceName in
the ingress rules. It can be a either real serviceName or an
annotation based action name when servicePort is &quot;use-annotation&quot;.</p>
</blockquote>
<p>In addition to the annotation we have added above, we continue to add conditions to annotations to filter the request but no need to have the host rule above.</p>
<pre><code>alb.ingress.kubernetes.io/actions.redirect-to-www: &gt;
    {&quot;Type&quot;:&quot;redirect&quot;,&quot;RedirectConfig&quot;:{&quot;Host&quot;:&quot;www.myhost.in&quot;,&quot;Port&quot;:&quot;443&quot;,&quot;Protocol&quot;:&quot;HTTPS&quot;,&quot;StatusCode&quot;:&quot;HTTP_302&quot;}}
alb.ingress.kubernetes.io/conditions.redirect-to-www: &gt;
    [{&quot;Field&quot;:&quot;host-header&quot;,&quot;HostHeaderConfig&quot;:{&quot;Values&quot;:[&quot;myhost.in&quot;]}}]
</code></pre>
<p>We modify the existing host rule you currently have to achieve the redirection.</p>
<pre><code>- host: www.myhost.in
    http:
      paths:
        - path: /*
          backend:
            serviceName: redirect-to-www
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: ssl-redirect
            servicePort: use-annotation
        - path: /*
          backend:
            serviceName: eks-learning-service
            servicePort: 80
</code></pre>
<h2>Update for <code>networking.k8s.io/v1</code></h2>
<pre><code>- host: www.myhost.in
  http:
    paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: redirect-to-www
            port:
              name: use-annotation
</code></pre>
