Basically, i would like to have a subdomain or path go to some public url such as a reddit page or google document, but i have no idea how i would do that.
pretend i want to go to the traefik subreddit, i would like the following to [separately] take me there
t-reddit.mydomain.com
mydomain.com/t-reddit
these should take me to https://www.reddit.com/r/Traefik/
how would i do this? it should also be easy to add more different paths or subdomains, as i will copy-paste the example for other links.
edit: to be clear, i would like to do this in a dynamic file
cakiwi
August 29, 2020, 4:19pm
2
This is a job for the redirectRegex middleware.
I would make the regex very broad (^.*$
) and use it on the routes you want to redirect.
I have a ./rules/ directory for traefik, could you give me a couple of examples of a .toml or .y(a)ml that would do what I want?
cakiwi
August 31, 2020, 1:51pm
4
http:
routers:
one:
rule: (Host(`t-reddit.mydomain.com`) || (host(`mydomain.com`) && Path(`/t-reddit`)))
entrypoints: web
middlewares:
- redirect-reddit
service: dummy
middlewares:
redirect-reddit:
redirectRegex:
regex: ^.*$
replacement: https://www.reddit.com/r/Traefik/
# If you want a pemanent redirect
# permanent: true
services:
dummy:
loadBalancer:
servers:
- url: http://127.0.0.1:9999
Hey, thanks. I haven't used yaml files with traefik yet, but I think I understand how it works. (Looks much nicer than toml tho) and it works nicely!
Question: what is that dummy service for?
cakiwi
August 31, 2020, 2:31pm
6
Your routers need a service. This is one way of providing that in a self contained fashion.
You could enable ping --ping
on traefik and then use the ping@internal
as the service instead.