Stupid Simple PHP URL Shortener In Less than 10 Lines Of Code!

Read Time:1 Minute, 38 Second

Want a simple as to use custom domain name URL shortener for free. Well in todays post I’ve got just that and all in under 10 lines of PHP code.

Free URL Shortener PHP Code

Please take notice of this file structure – yourwebsite.com/go/index.php

Create a folder on your domain called go (this could be anything but for sake of tutorial lets create go)

Inside this folder create a file called index.php

Open index.php up and paste the code below into the file and hit save.

<?php
$shortlinks = parse_ini_file('links.txt');

if(isset($_GET['l']) && array_key_exists($_GET['l'], $shortlinks)){
    header('Location: ' . $shortlinks[$_GET['l']]);
}
else{
    header('HTTP/1.0 404 Not Found');
    echo '<meta http-equiv="refresh" content="0; url=https://imrandell.com">';
}
?>

You will now need to make a file inside of the go folder called links.txt

Open links text and add your links. You will see below I have included a sample using my own links, this will show you how this works.

As you can see we assign a short text first then the = then the URL to the website we want said short text to link to, Basic stuff 🙂

mte = http://funneledaffiliate.com
ate = http://autoviewz.com
banner = https://sharemyads.com
randell = https://imrandell.com
backlinks = https://oxaus.com
rogue = https://roguetoken.com

In order to use your new short links you would do something like this.

yourwebsite.com/go/mte

Here’s a demo I have already set up using this script – https://ecoincoop.com/go/mte

Conclusion

Personally this is really good for branding, as your now using your company domain to shorten your links instead of sites like bit.ly 🙂 What to say it’s a URL shortener, go shorten the heck out of the internet friends.

Leave a Reply

Previous post Make Your Own PHP Website URL Rotator In Under 10 Lines Of Code!
Next post Awesome Call To Action Widget Code