- I have a shortened URL from some documentation
- I would like to open the URL because I believe the URL has good information
- but I do not want to click the link until I can see the full URL
3 Answers
For Firefox:
- https://addons.mozilla.org/firefox/addon/short-url-expander/
- https://addons.mozilla.org/firefox/addon/url-revealer/
- https://addons.mozilla.org/firefox/addon/expand-url/
For Chrome based browsers:
- https://chrome.google.com/webstore/detail/preview-short-urls/lhnpeajamdliepjblldlghmpkohfjakb
- https://chrome.google.com/webstore/detail/unshortenit/lgmkbhnfldpklfakbcopgkkhonofficm
I've not tested any.
Curl: curl -s -I "$URL" | awk '/location:/{print $2}'
wget probably can do this as well (it has -d) but I'm half-asleep right now to read its manual.
-
See my comment on #736239dave_thompson_085– dave_thompson_0852025-05-16 22:44:48 +00:00Commented May 16 at 22:44
I found a simple elegant solution using shell command:
curl --head bitly.is/urlshortening|grep Location|awk '{print $2}'
explanation of the shell command:
curlwith--headgets only the HTTP headergrepgets you the line of text with URL valueawkprints you just the URL value- done
even shorter: curl --head --location bitly.is/urlshortening
The reason why using curl works is because the URL shortener is doing an HTTP redirect and so this solution uses the knowledge about how HTTP redirects work.
p.s. IMO curl is significantly better than a browser extension or third-party website because the curl solution is (1.) faster IMO than having to vet N browser-extensions/third-party-websites (2.) and the shell command is easy even for beginners (3.) browser-extensions/third-party-websites come and go.
-
1you can also actually extract that header field using curl. No need to manually look for the Location field. add a
-Lto your command lineMarcus Müller– Marcus Müller2023-02-20 18:50:08 +00:00Commented Feb 20, 2023 at 18:50 -
2@MarcusMüller that triggers a HEAD on the target URL, which may have undesirable side-effects. Extracting the Location field from the bit.ly HEAD avoids thatChris Davies– Chris Davies2023-02-20 22:05:57 +00:00Commented Feb 20, 2023 at 22:05
-
@MarcusMüller thanks i'll add that.Trevor Boyd Smith– Trevor Boyd Smith2023-02-21 18:43:39 +00:00Commented Feb 21, 2023 at 18:43
-
1
-Lor--locationactually performs the redirect, it does not "extract" what's in theLocationfieldEternal Dreamer– Eternal Dreamer2025-05-02 13:40:46 +00:00Commented May 2 at 13:40 -
HTTP header names are conventionally camelcase but officially are case-insensitive and some servers vary;
grep -i ^location:would be more robust. Or with gawk something likeBEGIN{IGNORECASE=1} $1~/location/{print $2}dave_thompson_085– dave_thompson_0852025-05-16 22:43:28 +00:00Commented May 16 at 22:43
Using GNU AWK (HTTP only):
echo 'http://bitly.is/urlshortening' |
awk 'BEGIN{
ORS="\r\n" # end printed lines with CRLF
IGNORECASE=1 # header names vary in capitalization
}
(gsub(/^http:\/\//,"")==0){ print "unable to use " $0; next }
{ domain = gensub(/\/.*$/,"","g") # e.g. bitly.is
path = gensub(/^[^/]*\//,"/","g") # e.g. /urlshortening
http_connection = "/inet/tcp/0/" domain "/80"
print "HEAD " path " HTTP/1.1" |& http_connection
print "Host: " domain |& http_connection
print "Connection: close\n" |& http_connection
while ((http_connection |& getline) > 0)
if(gsub(/^Location: /,"") > 0)
print
}'
This submits a HEAD request. I got the idea from this question on CodeGolf: https://codegolf.stackexchange.com/questions/61836/the-worlds-smallest-web-browser
This only works for link shortening services that support just HTTP (but I checked, and both bitly.is and tinyurl allow it!). There's probably a way to do HTTPS too (use /443 and...encrypt it somehow), but my knowledge doesn't go that far.
-
1Although many webservers will Postelianly accept that, the lines of an HTTP request header (or response header also) should end with CRLF not just LF, and there should be only one empty line following the header not two. Also header names may vary in capitalization, which gawk can handle easily with IGNORECASE=1 .dave_thompson_085– dave_thompson_0852025-05-16 22:45:27 +00:00Commented May 16 at 22:45
-
Thanks, didn't know that! Added both changes.wobtax– wobtax2025-05-16 23:56:48 +00:00Commented May 16 at 23:56