Www to non-www redirect, again

I know, there was many topics about www <-> non-www redirection.
Checked them all, but still can't make it work.

My docker-compose.yml file.

version: '3.8'

services:
  traefik:
    image: traefik
    command: 
      - --entrypoints.web.address=:80
      - --providers.docker
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: traefik/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`example.com`) || Host(`www.example.com`)"
      - "treafik.http.middlewares.www-redirect.redirectregex.regex=^http://www.example.com/(.*)"
      - "traefik.http.middlewares.www-redirect.redirectregex.replacement=http://example.com/$${1}"
      - "traefik.http.routers.whoami.middlewares=www-redirect"

I need to make redirection from www.example.com to example.com.

But instead every request is redirected to something like http://example.com/hhttp://example.com/thttp://example.com/thttp://example.com/phttp://example.com/:http://example.com//http://example.com... many times (loop).

What is wrong with my code?

I will answer myself.

There is typo in

- "treafik.http.middlewares.www-redirect.redirectregex.regex=^http://www.example.com/(.*)"

Should be traefik instead of treafik

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