What is url shortener?
Answer: URL Shortening

There are many posts about url shorteners on the internet, but I wanted to write this post to record my own thoughts.

For a good url shortener, it should have a short domain (e.g., t.ly, bit.ly).

Short domains can be quite expensive.

An alternative is to use a DNS server to map a short domain to a long domain.

However, in most cases, this is not necessary for me.

I just want to create a url shortener in my local network, so I am interested in using a local url shortener.

/etc/hosts

/etc/hosts is a file in Linux that can link a domain to an IP address.

For example, I can add the following line to /etc/hosts:

127.0.0.1      go

This allows me to access go in my browser.

When I enter go in my browser, it sends a request to 127.0.0.1:80 (you cannot specify a port in /etc/hosts because it works like a DNS server and can only link a domain to an IP address).

Code

Writing a url shortener is quite simple: just create an HTTP server that maps a domain to a URL.

You can write one yourself or take a look at my abcdlsj/golink implementation (Use SQLite3, With import/export features).

Run it

Run it as a daemon:

nohup golink &

View

golink screenshot

You also can add a Chrome Site-search to make it easier to use.

Chrome Site-search setting

End

This post doesn't include any code samples, as I believe that you can write it yourself for the purpose of learning or practicing a programming language.

The idea is from tailscale/golink, which relies on Tailscale Magic DNS. You can find more information here