tecnoysoft software and technology

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…

2 respuestas para “How to obtain the real URL behind a shortened URL using cURL

a tech writer

I didn’t know that was possible. It probably won’t work for those short urls with an ad wall.

Elías R.M.

Yes, you are right. This trick is based on the fact that the shortened URL normally do a redirect, so we can easily “capture the redirection”.

Comments are closed.