Skip to main content

Finding the original page for a post on Mastodon

Following the logged-out 302 Redirect takes you to the original post.

Let’s suppose I’m browsing my Mastodon timeline. Every post has a permalink to the copy of the post on my server. For example:

but the true permalink of this post is the one on the original server; in this case:

If I’m looking at the post in the Mastodon web app, I can get this URL with the “Open original page” or “Copy link to status” command.

Screenshot of a Mastodon post with the menu open, showing the 'Copy link to status' command highlighted.

What if I want to get that URL programatically?

At least on my server, trying to view my server-local permalink to the post when you’re not logged in will redirect you to the original post. This means we can find it by inspecting the redirect location:

$ curl --head --write-out '%header{location}' ''

This isn’t true in general, and might depend on server config – for example, trying this technique on redirects you to an interstitial page that asks you to confirm you really want to leave

$ curl --head --write-out '%header{location}' ''

It turns out there are some security issues related to redirects like this, so even on my server this technique might not last forever.

I was originally investigating this for my ;furl text expansion macro that inserts a link to the URL of my frontmost browser tab. I wanted a way to ensure Mastodon links always used the link to the original status, not my server’s copy of it. This worked as an initial fix, but if this is an issue in future I might need to look at using the Mastodon API.