menu
Custom GitHub URL
Thursday, Jun 25, 2020

Intro

Do you often find yourself typing git clone https://github.com/yourusername/repo? I did.

In this tutorial, I will show you how I redirect from my custom domain m4x.uk to github.com/maxisme/ using Traefik.

For example, this allows me to easily access my GitHub repo, max.me.uk, located at github.com/maxisme/max.me.uk by visiting m4x.uk/max.me.uk.

Setup

In my Traefiks main config I have a provider for Files:

traefik.toml

[providers]
    [providers.file]
        directory = "/etc/traefik/rules/"
        watch = true

Using a new file provider I created a simple middleware to redirect my custom domain m4x.uk/repo to github.com/maxisme/repo using Traefiks redirect regex.

/etc/traefik/rules/github.toml

[http.routers.github]
    rule = "Host(`m4x.uk`)"
    middlewares = ["github-redirect"]
    service = "empty-service"
    [http.routers.github.tls]
        certResolver = "letsencrypt"

[http.services.empty-service.loadBalancer]

[http.middlewares.github-redirect.redirectRegex]
    regex = "m4x.uk/(.*)"
    replacement = "github.com/maxisme/${1}"
    permanent = true
~
~
comments powered by Disqus