Short-URL's using Caddy Server

Short-URL's using Caddy Server

Use Caddy server to shorten custom URL's

Vision:

  1. resolve only my custom short links (No need to tech junk)
  2. not a public, internet-facing service (No overkill)
  3. The most minimal setup I could think off

Requirements:

  1. A domain name that will be the root for a subdomain i.e url.domain.org/*
  2. A webserver with a public-facing IPV4 address
  3. A wee bit of Linux knowledge
  4. Install caddy server on your web server (I use Ubuntu 20.04)
  5. Point the IP address of the webserver to your subdomain

Caddyfile config

# /etc/caddy/Caddyfile

 url.domain.org {   # replace it your subdomain

    map {path} {redirect-uri} {
        /deals     https://www.govdeals.ca
        /voice     https://www.voiceflow.com

        /killer    https://www.youtube.com/watch?v=_6ZGgdeWfSM

        # will add new ones here like the above
        # ...
    }

    # this below code is required to actually make the above `map` work

    @hasRedir expression `{redirect-uri} != ""`
    redir @hasRedir {redirect-uri}

    # code below is to set the default response if the requested URL isn't here
    respond "Error: unknown short URL ... :("

Note: Please remember to restart the Caddy server every time you update the site list

Le Fin

That's all folks. I hope you enjoyed this blog post