Forward from non-www to www

Hello,

I am trying to forward from a non-www address to a www version. I've followed a lot of the documentation present and cannot seem to get this to work. Below is an example of my ingress and middleware charts:

# Rewrite Rule to www
{{ range .Values.wwwRedirect }}
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: myDomain
  labels:
    app: {{ $.Release.Name }}
spec:
  redirectRegex:
    regex: "^https?://(?:www\\.)?(.+)"
    replacement: "https://www.${1}"
    permanent: true
{{ end }}


{{ range .Values.wwwRedirect }}
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: {{ .name }}
  labels:
    app: {{ $.Release.Name }}
spec:
  entryPoints:
    - web
    - websecure
  routes:
  - match: Host(`{{ .name }}`)
    kind: Rule
    middlewares:
    - name: myDomain  
    services:
    - kind: Service
      name: {{ $.Release.Name }}
      namespace: {{ $.Release.Namespace }}
      passHostHeader: true
      port: 80
      scheme: http
  tls:
    secretName: {{ .name }}
{{ end }}

I know it is using the middleware chart because when I disable permanent it doesn't force the 301. It just isn't rewriting the domain I pass in. I.e

I am going to https://mydomain.com and the expected solution is that it goes to https://www.mydomain.com

Unsure what I am missing here so any help would be greatly appreciated.

Nevermind, I figured it out. Something was wrong with some monitoring software and was preventing it from reading my /etc/hosts where I had traffic for the domain pointed to.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.