External domain redirection without backend proxy using Traefik v1.x

Hi everyone!
Happy to join the Traefik community!
I'm facing a https redirection issue that I can not solve. I would like to redirect from domain1.com , domain2.com , domain50.com to external.com but without a backend (just a simple 301 redirection). I did heard it's possible via some entrypoint regex (I did tried without success) but I have many domains that I want to redirect, groups of them to specific ones.

Here the use case on the top of https:

d1.com, d2.com, d3.com → x1.com
d4.com, d5.com, d6.com → x2.com

For both cases no backend needed just 301 only.

I understand that there is a progress on v2 for multiple regexs but I'm using now v1.7.12 and I have found no solution for this.

References:

You help will be very appreciated!

This looks relevant:

Thanks!
As far as I know, a frontend always needs a backend or?. Anyway I will try to use a fake backend soon.

I have tried but It works just for one redirection group d1.com, d2.com, d3.com → x1.com but not for the other. For the second one when I do some request to then I don't get any response (no status code o something). I'm using docker swarm.

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
    permanent = true

  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[file]
watch = true

[backends]
  [backends.fake]
    [backends.fake.servers.s1]
      url = "http://1.2.3.4"

[frontends]
  [frontends.r1]
    entryPoints = ["https"]
    backend = "fake"
    [frontends.r1.redirect]
      regex = "https://(www.)?(d1.com|d2.com|d3.com)(.+)?"
      replacement = "https://www.x1.com$3"
      permanent = false

  [frontends.r2]
    entryPoints = ["https"]
    backend = "fake"
    [frontends.r2.redirect]
      regex = "https://(www.)?(d4.com|d5.com|d6.com)(.+)?"
      replacement = "https://www.x2.com$3"
      permanent = false

Partially solved combining frontend settings (fake backend) and one entryPoint redirect.
But for only two groups, what happen if I have more without backend?

I am also interested by your findings joseluisq.

I know I could start simple Nginx containers with something like:

server {
    listen 80;
    server_name site1.tld;
    return 301 https://site2.tld;
}

But it felt wrong with Træfik.

How did you achieved to make it work with two groups (both d[1-3].com AND d[4-6].com)?

@CDuv I have done basically via one redirection regex using one frontend + fake backend for the first group and then for the second one just one redirection at the entrypoint level because entrypoint also supports redirection based on regexs.

Here the complete config which worked for me:

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
    permanent = true

[entryPoints.https]
  address = ":443"
    [entryPoints.https.redirect]
      # Group 1
      regex = "https://(www.)?(d1.com|d2.com|d3.com)(.+)?"
      replacement = "https://www.x1.com$3"
      permanent = true
    [entryPoints.https.tls]

[file]
watch = true

[backends]
  [backends.fake]
    [backends.fake.servers.s1]
      url = "http://1.2.3.4"

[frontends]
  [frontends.r2]
    entryPoints = ["https"]
    backend = "fake"
    [frontends.r2.redirect]
      # Group 2
      regex = "https://(www.)?(d4.com|d5.com|d6.com)(.+)?"
      replacement = "https://www.x2.com$3"
      permanent = false

If you have applications with docker backends for example there is no problem because you can add redirections directly via docker labels per service.
The problem is if you have many groups without backends to apply external redirections.
Traefik v2 plans to support Multiple entry regex redirects - Issue #723 but it's in alpha yet.

We plan to rewrite the redirection system. The entry points are a completely different notion in the v2 than in the v1.
For now, the issue #723 is not in the scope of the v2.

Thanks joseluisq, nice hack :wink: