Rewrite all non www traffic to www subdomain

0 votes

I'm trying to redirect all non-www traffic to www subdomain for url canonicalization. So all traffic on example.com should be rewritten to . I can't seem to figure out how though.

My Ingress:

{
  "apiVersion": "extensions/v1beta1",
  "kind": "Ingress",
  "metadata": {
    "name": "example-staging",
    "annotations": {
      "ingress.kubernetes.io/rewrite-target": "/",
      "kubernetes.io/ingress.global-static-ip-name": "example-static-ip"
    }
  },
  "spec": {
    "rules": [
      {
        "host": "www.example.nl",
        "http": {
          "paths": [
            {
              "path": "/",
              "backend": {
                "serviceName": "example-service",
                "servicePort": 80
              }
            }
          ]
        }
      }
    ]
  }
}
Oct 1, 2018 in Kubernetes by lina
• 8,220 points
593 views

1 answer to this question.

0 votes

Try adding a second Ingress for example.nl that uses the ingress.kubernetes.io/configuration-snippet annotation to add the 301.

{
  "apiVersion": "extensions/v1beta1",
  "kind": "Ingress",
  "metadata": {
    "name": "example-staging-wwwredir",
    "annotations": {
      "ingress.kubernetes.io/rewrite-target": "/",
      "ingress.kubernetes.io/configuration-snippet": "return 301 $scheme://www.example.nl$request_uri;"
    }
  },
  "spec": {
    "rules": [
      {
        "host": "example.nl",
        "http": {
          "paths": [
            {
              "path": "/",
              "backend": {
                "serviceName": "example-service",
                "servicePort": 80
              }
            }
          ]
        }
      }
    ]
  }
}
answered Oct 1, 2018 by Kalgi
• 52,360 points

Related Questions In Kubernetes

0 votes
1 answer

What all packages do i need to install to use kubernetes on my machine?

Install below packages on all of your ...READ MORE

answered Jul 11, 2019 in Kubernetes by Sirajul
• 59,230 points
851 views
0 votes
1 answer

how to drain the traffic from a pod?

When we take the node for maintenance, ...READ MORE

answered Jul 17, 2019 in Kubernetes by Sirajul
• 59,230 points
2,052 views
0 votes
1 answer

What all components run inside a worker node to provide a kubernetes runtime environment?

Node components run on every node, maintaining ...READ MORE

answered Jul 24, 2019 in Kubernetes by Sirajul
• 59,230 points
952 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,330 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 6,945 views
0 votes
1 answer

How to rewrite all non-www traffic to www subdomain?-kubernetes ingress

The ingress.kubernetes.io/rewrite-target is used for rewriting the request URI, ...READ MORE

answered Sep 11, 2018 in Kubernetes by Kalgi
• 52,360 points
3,678 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP