Another 5-minute project. I needed a pretty URL to print on a QR code that would redirect the user into another URL of my choice, an URL that I might want to change in the future so in essence I needed the services of almost any URL shortener out there but at the same time I did not want to rely on a paid third party service for such a simple thing so I decided to make my own.

JSRedir is an URL shortener that requires no server-side code at all, instead relying on static .json files and client side JavaScript. It can be deployed with minimal HTTP server configuration.

Installation

Just make the repository contents available as static files. Nothing more.

Configuring nginx

An example configuration for using jsredir on nginx where the shortener URLs lie under the /s/<short link> paths. Any and all links under this prefix will serve the index.html file which will in turn extract the short link info from the URL itself on the client.

location /s/ {
    root   /path/to/jsredir;
    index  index.html index.htm;
    try_files $uri /s/index.html;
}
location /s/links/ {
    root /path/to/jsredir;
    add_header Cache-control "no-store";
}

At work!

This link should take you to the main page, meanwhile this other link should just show you a clickable link instead, for debug purposes.

Oddly enough, the “short” link is longer than the original link in this case but the main purpose of the project is having “pretty” links ;)