URL Redirect abc.com to xyz.com

Hi I am using docker-compose for Traefik and for a domain I want to redirect it to different url. There is no service running in short I want to use Traefik to forward the URL to a different URL.

I am getting error too many redirects. Can someone help please?

labels:
      - "traefik.http.routers.catchall.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.catchall.entrypoints=web"
      - "traefik.http.routers.catchall.middlewares=redirect-to-https"
      - "traefik.http.middlewares.domain.redirectregex.regex=^https://abc[.]com/(.*)"
      - "traefik.http.middlewares.domain.redirectregex.replacement=https://xyz.com"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.traefik.rule=Host(`dashboard.abc.com`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.tls.certresolver=myhttpchallenge"
      - "traefik.http.routers.traefik.entrypoints=websecure"

Hello,

I created a small example, with self-signed certificates and some local domains.

The Traefik dashboard is on https://traefik.localhost

There is a redirection from https://abc.localhost (or http://abc.localhost) to https://xyz.localhost

I added a whoami to simulate the xyz.localhost, it's just to have a working example.

version: '3.7'

services:

  traefik:
    image: traefik:v2.3.1
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    command:
      - --log.level=INFO
      - --api

      - --providers.docker.exposedbydefault=false
      
      - --entrypoints.web.address=:80
      - --entrypoints.web.http.redirections.entryPoint.to=websecure
      - --entrypoints.web.http.redirections.entrypoint.scheme=https

      - --entrypoints.websecure.address=:443
      - --entrypoints.websecure.http.tls=true
    labels:
      traefik.enable: 'true'

      # Dashboard
      traefik.http.routers.traefik.rule: Host(`traefik.localhost`)
      traefik.http.routers.traefik.service: api@internal

      # Redirection from https://abc.localhost (or http://abc.localhost) to https://xyz.localhost
      traefik.http.routers.domain.rule: Host(`abc.localhost`)
      traefik.http.routers.domain.service: noop@internal
      traefik.http.routers.domain.middlewares: to_xyz
      traefik.http.middlewares.to_xyz.redirectregex.regex: ^https?://abc\.localhost/(.*)
      traefik.http.middlewares.to_xyz.redirectregex.replacement: https://xyz.localhost/$$1

  # just to have xyz.localhost
  whoami:
    image: containous/whoami:v1.5.0
    labels:
      traefik.enable: 'true'

      traefik.http.routers.whoami.rule: Host(`xyz.localhost`)
1 Like

Thank you so much Idez. This I would not have been able to figure out without adding a dummy service.

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