Redirecting www to non-www with Kong Ingress Controller

98 views Asked by At

Hello Stack Overflow community,

I'm in the process of setting up a Kong Ingress Controller for my Kubernetes cluster, and I'm looking for guidance on how to properly redirect www domain requests to the non-www domain.

I haven't attempted any specific configurations yet, as I'm unsure about the best approach with Kong Ingress. I'm seeking advice on the recommended way to achieve this redirection.

Can someone provide a step-by-step guide or suggest the necessary annotations to add to my Kong Ingress configuration for redirecting www.example.com to example.com?

Thank you for your help!

Our current Ingress file:

I have tried adding a server block to the configmap.yaml file, but it's not working. Here is the server block I have added:

server {
  listen 80;
  server_name www.example.com
  rewrite_log on;

  # Redirect www requests to base domain
  return 301 $scheme://{{ .Values.ingress.basedomain }};
  proxy_set_header Host $host;
}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sonar
  annotations:
    konghq.com/strip-path: 'true'
    configuration.konghq.com: |
      rewrite-target: /
spec:
  ingressClassName: kong
  rules:
  - host: "www.example.com"
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-sonarqube-sonarqube
            port:
              number: 9000
  - host: "example.com"
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-sonarqube-sonarqube
            port:
              number: 9000```
0

There are 0 answers