How To Create Your Own URL Shortening Service
Creating a private URL shortener for your business or website gives you more power over traffic analytics and other activity.
If you've ever tried to chop down a 160-character tweet, you know how handy a URL-shortening service can be. With only 160 characters, every character counts.
Public URL-shortening services like bit.ly and is.gd are great for the average Twitter user. But if you're a serious blogger or company seeking to manage your brand online, you should definitely think about creating your own shortening service. That way you'll be able to protect your brand and better analyze traffic.
It only takes about 15 minutes to set up your own URL shortener. Here's how to do it. First, come up with a short but similar domain name. For this, I use the website http://domai.nr. Domain.nr lets you type in a word or name and do everything you need to register your new, shorter domain name.
Once you have that new short domain, download the latest copy of YOURLS.
Extract the downloaded file to a new subdirectory.
Now, navigate to the /includes folder and copy the file sample-config.php to /user/config.php. Open the config.php with your favorite text editor. You'll need to edit a few files before you upload it to your hosting provider.
Configure the database settings. Fill in the MySQL settings you will be using with your hosting provider. I highlighted the most critical of the settings you need to configure. Fortunately, the config file has some great comments that will make it easy for you to get through the process.
Now scroll to the bottom of the file to complete the configuration, including the site name, cookie key, and user password to log in. Be sure to create a password that's long and stronger than the one I use in the example below. That means a combination of numerals and uppercase and lowercase letters.
YOURLS is a simple .php /MySQL application; pretty much any hosting provider will work with it. Just grab your folder and upload it to the root of your new domain you purchased. In my example I'm uploading YOURLS to a subfolder off the root of my domain.
Now it's time to create the MySQL database YOURLS will use to store all the data in. Using the MySQL settings from the config.php file you created earlier, create your MySQL database on your host. On my host, this step is fairly easy. It will vary depending on your hosting provider. Check with your provider if you need help with this step.
Once your files are all uploaded and your MySQL data is configured, navigate to your new site and click the Install YOURLS button on that page.
If you did everything correctly, you should get a screen full of green check boxes.
Enter the Username and Password you configured earlier in your config.php file.
Optional: Once logged in, I recommend you enable hyphens. Under Allow Hyphens in Short URLs, click Tools and Activate.
Now it's time to test out your new service! Click the Admin Interface Link at the top of the page and then type in a URL and Custom short URL.
One of the great things about YOURLS is its reporting capability. Once you have created your short URL, just click the Report button at right to view everything from traffic stats to traffic sources.
Another way to get stats is to navigate directly to the page and add a + at the end of it.
YOURLS also comes with several different bookmarklets that let you easily shorten any webpage you visit. Just head over to the Tools page. Click and drag the bookmarklets to your browser's toolbar.
Now visit any website and click the bookmarklet to automatically create a short URL for that page. Remember you need to be logged into the YOURLS site for the bookmarklets to work.
If you're a blogger who uses Wordpress, you also should install a free plugin that will automatically create a shortened URL for each post you publish. It's possible to configure that plugin to automatically publish each post with the short URL to Twitter, too. Because YOURLS is based on PHP and CSS, it's super easy to configure.
Based in Seattle, Steve Krause is a senior contributor at BYTE. Follow him @krausesteve and email him at [email protected].
About the Author
You May Also Like
2024 InformationWeek US IT Salary Report
May 29, 20242022 State of ITOps and SecOps
Jun 21, 2022