de

Alias for your Mastodon handle—in the Kirby config.php

Post #8, posted in
  • How to

On Mastodon, there are a few posts about how to implement a custom alias for your actual Mastodon handle using different setups already. Phil Hawksworth wrote about it here (using a Netlify redirect rule) and Trey Piepmeier here (utilising the Redirects plugin in Kirby CMS).
This post here shows you, how you can achieve the same thing with a route in your Kirby config—without any plugin.

After implementation your handle might look something like this: @nils@nilsmielke.me
rather than this: @nilsmielke@det.social.
One of the advantages being, that you will be able to keep that custom handle even if moving to another Mastodon instance.

In your Kirby config.php add a new route like so…

<?php
return [
    'routes' => [
        [
            'pattern' => '.well-known/webfinger',
            'action'  => function() {
                if (get('resource') == 'acct:nils@nilsmielke.me') {
                    go('https://det.social/.well-known/webfinger?resource=acct:nilsmielke@det.social', 200);
                }
            }
        ]
    ]
]

…and it works beautifully:

Mastodon search result showing “@nilsmielke@det.social” for the search term “@nils@nilsmielke.me”.

Wunderbar! 🎉

You gotta use your own alias and handle, of course!1!!

And now what?

Whenever you switch Mastodon instances in the future, your handle will inevitably change.
If you update above route in your Kirby site accordingly, your alias will point there, thus preventing you from having to get new business cards printed—or change whatever else you put your handle on.