Files
hpr-knowledge-base/hpr_transcripts/hpr2904.txt

157 lines
10 KiB
Plaintext
Raw Normal View History

Episode: 2904
Title: HPR2904: DIY URL shortening
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2904/hpr2904.mp3
Transcribed: 2025-10-24 12:59:15
---
This is HBR episode 2904 entitled DIY URL shortening, it is hosted by Klaatu and in about
12 minutes long and Karina Klinflag.
The summary is quick tip on how to shorten a new URL without a series R.S.
This episode of HBR is brought to you by archive.org.
Support universal access to all knowledge by heading over to archive.org
forward slash donate.
Hi everyone, this is Klaatu, you're listening back with Public Radio.
This episode I'm going to do a quick little short tip idea that I had.
I mean it's something that you probably could think of yourself but maybe you
haven't.
It's something that every time I sort of bring it out and play that card people think,
wow that's a really great idea, I never thought of that.
So I figured it's probably actually worth doing an episode on because while on one hand
I keep thinking this is super obvious, why am I talking about this?
On the other hand it's clearly something that people enjoy when I bring it up.
So what is it?
Well the thing is we've all seen those URL shortners, right?
I used to be all the rage like five years ago, I feel like I don't see them quite as
much now but they were a big thing for a while and you'd see them as bit.ly.
URL shortners, you'd see them as I think another one was Owl Lee, I think Google probably
had one.
Like I said, they were kind of all the rage, it seemed like everyone had them for a while.
Maybe there's still a thing on Twitter, I don't know because you've got that character
limitation.
I don't really, I don't do Twitter so I don't know what's going on in Twitter.
I've opt for the free and open source service mastodon, you should check it out mastodon.social
for more information.
So anyway, you've got these URL shortners where you have some long, ugly, horrible link,
you want to make it memorable.
This could be anything from, I don't know, your host record at Hacker Public Radio where
you can go into your, into the complete episode listing in Hacker Public Radio and then
click on on the host and then you get all of the episodes recorded by that host.
So that's kind of, for instance, for me, that's a, that's sort of a good resume material.
I might want to link it directly to that if I'm pitching myself to someone as a podcaster.
Maybe I would say, hey, go to this link bit.ly slash Q5LT0 and you'll see all of my, well,
that's stupid, right?
That's a, that's a horrible URL shortner.
I mean, it does work.
It's just not very memorable.
It doesn't roll off the tongue and there might be services out there.
Maybe it's come to a point now where you go to your URL, you are a shortner and they
have vanity, shortening, ability so you can do bit.ly slash clattu underscore HPR.
I don't know.
But the point being the default generally are these short URLs that are randomized, sort
of out of necessity and you don't necessarily have any control over what they are and certainly
you don't have ownership over the thing providing the shortened URL.
So what I do and what I've done for quite some time now is I simply make my own.
How do you make your own?
It's actually a lot easier than you might, might think.
So if you have a hosting plan at all, then you can like with a domain name and of course
you can get free domain names at places like freenom.com and probably other places you
can get the dot tk or the dot ml or the dot gq or qg or whatever domains for zero dollars
and then you can throw them somewhere on a server.
It could be your own Raspberry Pi in your living room.
It could be a cheap hosting plan provided by any number of perfectly good hosting providers
such as, for instance, an honest host.com, you should check them out.
And now you have essentially a URL shortening service.
How you may ask, well, it's a simple command.
So first of all, what I do is I do, well, I go onto the, onto my domain, whatever it
might be.
In this case, I'll use gnewworldorder.info as an example.
So SSH, gnewworldorder.info, and then I make a directory called portal.
So in the public underscore HTML or the WWW folder, whatever your hosting provider sort
of, whatever convention they, they provide, you make a directory called portal.
Or if you want it really short, it could just be you, for instance, the letter U. And
you know from now on that anything gnewworldorder.info slash U is the URL shortened.
A version of something and then slash and then some keyword.
So this is the shortened, this is the vanity shortened URL that you want to use.
So for instance, if I am creating a, a, a, a pointer to my host identity on hacker
public radio, or the list of all of my episodes on hacker public radio, then I could do,
W, you know, make der, WWW dot, or slash rather, U slash HPR, and that would be it, right?
So that's the destination.
When I send people, when I want to refer to myself as an HPR host, I, I'm going to send
people to gnewworldorder.info slash U slash HPR.
Now if I was sending them to my podcast on fantasy lore, then I might send them to
gnewworldorder.info slash U slash, I don't know, fantasy or chronicles, whatever,
lore maybe.
That would be good.
L-O-R-E, that would be good.
And from there, you simply do a simple HTTP redirect.
Now the way that I do that, once again, I do it with a, with a shell script.
I do it over SSH.
So for instance, so the make directory command by the way would be SSH space example.com.
Again, that would probably be gnewworldorder.info for me.
So SSHexample.com, make der, WWW slash U slash HPR, or lore, or whatever, shortened URL
you are making.
So the WWW slash U, that already, always exists, that's always there, right?
The, the slash something is the, the vanity URL shortener key that you want to use.
Got it?
Okay, cool.
So now the, the, the, the next command would be an SSH command again, but it would be echoing
some, some, some, some HTML code into WWW slash U slash HPR slash index.html such that when
you send someone to gnewworldorder.info slash U slash HPR, by default, the web server opens
any available index.html it finds in the directory, which it does.
And then it uses, it, it detects in the, uh, in the HTML an, an HTTP redirect to the,
whatever address I want to redirect to.
What that looks like depends on how you're doing it.
Again, I do this with a shell script, so I don't have to worry about all the details,
but I'm going to give it to you in the, in the, the raw format, if you want to create
a shell script that does it, then you can do that as well.
So it would just be SSHspaceExample.com or whatever your destination is, your host, uh,
and then echo, space, double quote, backslash, double quote.
So that, that's, that's, that's two double quotes, kind of in a row, but one is escaped.
And that's very significant because the, the first double quote is for our SSH command
right now, the, the second one, the one within escape is the one for the, is the, is for
the command that's being run on the server on the, on example.com.
So double quote, backslash, double quote, and then some tags, for instance, HTML, that's
a tag.
So greater than HTML, less than, greater than title, less than shortened URL, and then close
the title, and then open a head tag.
So greater than head, less than, and then meta, HTTP dash a quiv equals single quote,
refresh, close single quote, space content equals single quote, zero semicolon, URL equals.
And then in this case, HTTP colon slash slash hacker, public radio dot org slash correspondence.
PHP question mark host ID equals 78, close quote, that is close single quote, and then close
self, self close this meta tag, so forward slash greater than, or whatever that is greater
than whichever one that is, and then close the head tag, and then close the HTML tag,
and then again, backslash double, double quote, to escape that, and then a double quote
to, to close that space, backslash, redirect, WWW slash portal slash, or rather WWW slash
U slash HPR slash index dot HTML, and that's it.
Now you have echoed the HTTP redirect into a destination file in WWW slash U slash HPR
slash index dot HTML, and so when someone goes to that location, it will automatically detect
that there's an index dot HTML, which will automatically detect that there's a redirect,
which will take the user to your actual destination URL.
It's a really simple trick, it's like I say pretty obvious, but it's one of those things
that I think a lot of people don't, don't think about until, until they're, until it's
done by someone else, you see it done, and then you think, oh my gosh, that's such an obvious
way, obviously a better way to quote unquote shorten a URL, because that way you've got
some kind of, you've got your brand, ownership, or whatever, you've got your own domain that
maybe you feel some affiliation with, and you've got something more memorable, because
it's a word instead of a string of random letters and numbers, and you can also control
how long it remains, how long it exists, and when you need to redirect it again, you
can go in and adjust the HTTP redirect, so there's a lot of ownership there that you don't
get otherwise, so that's my quick tip, like I say, it's pretty simple, you can do it a
variety of ways, I mean, I just do it with a script after having done it with raw SSH
for way too long, finally realized it was dumb, and I just do it with a script now, because
I kept doing the escape strong, but you could write something in, I don't know, any number
of languages to make it a mere command away, and it would be fast and easy, and a lot
simpler, probably than using one of those weird URL shortening services, so I hope that
helps, thanks for listening, and I'll talk to you next time.
You've been listening to Hacker Public Radio at HackerPublicRadio.org, we are a community
podcast network that releases shows every weekday, Monday through Friday, today's show,
like all our shows, was contributed by an HPR listener like yourself, if you ever thought
of recording a podcast, then click on our contributing to find out how easy it really
is.
Hacker Public Radio was founded by the digital dog pound and the Infonomicon Computer Club,
and is part of the binary revolution at binrev.com.
If you have comments on today's show, please email the host directly, leave a comment on
the website, or record a follow-up episode yourself, unless otherwise state it, today
show is released on the create of comments, attribution, share a like, 3.0 license.