Issues with redirection to an other subdomain with RedirectRegex

Hi all,

this is my first post here :slight_smile:

I'm having trouble with redirection of my files in Traefik, and I'm hoping someone can help me out.

My task is to redirect

  • from: http(s)://(www.)*
  • to:*

Here's what I'm running:

  • WordPress in Docker Compose with Traefik2.9
  • MinIO in a separate Docker Compose file
  • I'm using the following labels:
  traefik.enable: true
  traefik.http.routers.wordpress-app.entrypoints: web
  traefik.http.routers.wordpress-app.rule: Host(``,``)
  traefik.http.middlewares.wordpress-app-https-redirect.redirectscheme.scheme: https
  traefik.http.routers.wordpress-app.middlewares: wordpress-app-https-redirect,redirect-baseimages-to-data
  traefik.http.routers.wordpress-app-secure.entrypoints: websecure
  traefik.http.routers.wordpress-app-secure.rule: Host(``,``)
  traefik.http.routers.wordpress-app-secure.tls: true
  traefik.http.routers.wordpress-app-secure.tls.certresolver: myresolver
  traefik.http.routers.wordpress-app-secure.service: wordpress-app 80 proxy
  traefik.http.middlewares.redirect-baseimages-to-data.redirectregex.regex: ^https?://(www.)?openhdfpv\.org/wp-content/BaseImages/(.*)
  traefik.http.middlewares.redirect-baseimages-to-data.redirectregex.permanent: true

The URL works fine, but when I try to access, I get a 404 error.

I've tried a couple of things to fix this, but nothing seems to work. Here's what I've done so far:

  • Checked that the regular expression and replacement in the redirect-baseimages-to-data middleware are correct.
  • Changed the order of middlewares
  • Checked that the files are available on the target server at the correct location.

However, none of these solutions (that I remembered) have worked. I'm not sure what else to try. Does anyone have any ideas?

Thanks in advance for your help!

First, I would try using Host() with || (β€žorβ€œ):

Host(``) || Host(``)

Second, enable Traefik debug log to see what’s happening.

Thanks @bluepuma77

I went through the logs and found a relevant entry:

time="2023-02-18T00:49:03Z" level=debug msg="Creating middleware" routerName=wordpress-app@docker entryPointName=web middlewareName=redirect-baseimages-to-data@docker middlewareType=RedirectRegex
time="2023-02-18T00:49:03Z" level=debug msg="Setting up redirection from ^https?://(www.)?openhdfpv\\.org/wp-content/BaseImages/(.*) to${2}" entryPointName=web middlewareName=redirect-baseimages-to-data@docker middlewareType=RedirectRegex routerName=wordpress-app@docker
time="2023-02-18T00:49:03Z" level=debug msg="Adding tracing to middleware" middlewareName=redirect-baseimages-to-data@docker entryPointName=web routerName=wordpress-app@docker

Changing the Host() labels to use || didn't fixed the issue for me.

Here is the access.log:

[18/Feb/2023:07:49:23 +0000] "GET /wp-content/BaseImages/hello.jpg HTTP/2.0" 404 87495 "-" "-" 12271 "wordpress-app-secure@docker" "http://<internal_wordpress_ip>:80" 865ms

Can you check the Wordpress logs, is Wordpress receiving requests (with wrong path)?

Good point, I haven't checked so far.

"GET /wp-content/BaseImages/hello.jpg HTTP/1.1" 404 57205 "" "<browser_stuff>"

Looks like it's going straight through.

If you want to try regex: regex101


I had only ${2} there, but it's actually $${2}

Did you miss to assign the middleware?


If you want to use multiple middlewares on a router, use , to separate them.

1 Like

Tank you very much @bluepuma77 :blush::+1:
It's working now.

Had to assign the middleware to


and not to


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