How to obtain the real URL behind a shortened URL using cURL

Now we will try to explain you how to know the destiny URL of an shortened URL, like used in Twitter and other social networks, using cURL (Curl)

¿What is cURL?

Curl is a command line tool and a library that allows you to make network request using URL syntax, it supports the more common protocols, like http, https, ftp, etc. It is avalible as librery and as command line tool, so we can execute it directly or use it form our source code. It is also available for PHP.


If you are using a Debian based GNU/Linux distribution, it can be installed using the following command as root:

# apt-get install curl


To do it, type the folowing command on your terminal and you will get the real destiny of the shortened URL:

$ curl -sLI http://shortened_url | grep -i Location

The option “s” tells to curl to be silent, so will not print the “download” progress, “L” option tells that Curls must follow all redirections and “I” to download only the HTTP header, that is all we need. Lastly, we use grep to get header line that have redirection URL.

As an example we have taken a “GNU Social” shortened URL and this was the result:

Linux gnu blog cURL PHP

And it is all by now, we hope it will be useful for you…


Este es un espacio para el debate. Dada la importancia de los comentarios como espacio de participación, te pedimos por favor que leas detenidamente nuestras normas de participación.

Leave a Reply

Your email address will not be published. Required fields are marked *