Ridirect www to apex domain

Hey all,
I have Traefik v2 running on Kubernetes with Kubernetes CRD and Ingress settings.
I was wondering if there is a an elegant way either with Kuberntes CRD or traefik configuration to redirect from www to our main domain (apex without www).


Hello guysoft, thanks for dropping by. Please check this post and let us know if the solution provided there works. It's also worth noting that when using the CRD, you may need to adjust the regex as noted here.

1 Like

Thanks @notsureifkevin for pointing me the the right thread, will ask there, since I am not sure how to set the labels correctly in kubernets for . I am not sure in the context of kubernetes if the section goes in to the IngressRoute or to a deployment part as a static configuration.

Hey so it didn't work out of the box, and the regex in the post had errors (namely the group numbers were wrong, and also the other line had to be changed).
I fixed it and this middlware works for me:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
  name: redirect-to-nonwww
  namespace: default
    regex: ^https?:\/\/(?:www\.)?(.+)
    replacement: https:\/\/\${1}
1 Like