Creating your own short URLs with blogdown
bit.ly, but personalised
By Harshvardhan in R package blog
March 24, 2022
A few days ago I shared my personal Zoom room link to a few people: https://www.harsh17.in/zoom. The neatness of this in comparison to something like https://zoom.us/j/99672273048?pwd=eXV5R2pBR0FqNlBUWmtLdCt6THl3dz09 was amazing. It had two immediate effects:
- Sharing Zoom link wasn’t a tedious task anymore. I could type it anywhere from my memory.
- People started taking my Zoom calls more seriously. I’d like to believe it was due to my content but the short URL certainly had an effect.
How did I do it?
R is amazing and can easily be extended to new functionalities. Blogdown is an R package for creating personal websites.
You can create your own set of URL redirects in Blogdown. Instead of typing long URLs, you can create your own custom short URLs of the form yourwebsite.com/shorturl
.
Step 1
Go to your folder /static/
located in your personal website folder. It may or may not have any content already. If you do not have that folder, create one right beside other folders such as content
, layout
and themes
.
Personal website directory. Create a folder
static
here if you don’t have it already.
Step 2
Open your text editor (Notepad in Windows and TextEdit in MacOS) and create a new file named _redirects
with no extension. Your computer will tell you add an extension, ignore the warning and go ahead.
Step 3
Write your URLs there. Start with the short URL and then long URL with at least two tab spaces. See my example below.
Remember to leave appropriate space (at least two tabs) between the short and long URLs. Handle ‘
/
’ properly.
You can have comments starting with #
.
That’s all!
Commit your edits to Github and give it two minutes to deploy via Netlify. Try your short URL and it should work.
Some Tips
Create short URLs for articles or website you frequently share or visit. For example, I have created short URLs for my social media profiles because twitter.com would take me to the home page instead of profile page.
Create a short URL for your Zoom room link. This one is a no-brainer.
Create short URLs for content you share often. I frequently share link to my Newsletter and my article on IPM admissions. So, I created their short URLs that I can type as I go.
Troubleshooting
Here are some tips in case you run into some troubles.
-
Make sure you leave at least two tab spaces between short URL and long URL.
-
/
matter. See that you are using the right short URL with or without/
at the end. -
Commit to Github and wait for results. Netlify takes a few minutes to deploy your new site.
If you still have troubles, write to me at hello@harsh17.in and we can resolve it together.