DEV Community

manish srivastava
manish srivastava

Posted on

404 Error as Url Shortner without db

Hey,
Recently I created a small script with just few lines of code as Url Shortner.

First how it works then where I am using it.

  1. How it works

This is my url : https://getus.live

Now anything you type like
https://getus.live/yourname

Will redirect it to default 404 page as nothing is 'yourname' on server / linked to server.

I modified 404 default page to catch anything after my domain name. In this case /yourname is catched by 404 page and array with key ( yourname) will be redirected to "value" of the key. This value is long url.

Workflow:
In index page I asked the user to give the long url and key.
This will write a array with key and value. The key here is /yourname and value will be longurl.

To see in action visit
https://getus.live
Try yourself.

  1. Where I am using it

(1) Url Shortner
(2) Navigation System
(3) Referal System catching values etc
(4) Bash UI to run commands.

Bye!!!

Top comments (0)