Using a Redirect Rule to Resolve Mastodon's WebFinger requirement on a Subdomain

I kept running across a problem with my Mastodon instance where I was seemingly unable to follow other accounts. Reviewing Sidekiq logs revealed HTTP 401s for nearly every account I tried to follow.

After some poking and help from some very kind folks on a Mastodon admin Discord (@[email protected], specifically), as well as my host, I think I’ve resolved the issue. It seems to have been because I boched my webfinger redirect.

For some context, Mastodon relies webfinger as a method for clearly identifying users on remote servers. Since I have my Mastodon instance on a subdomain of alvani.me, but want my usernames to be in the @[email protected] format, I have to create a redirect for requests to

https://alvani.me/.well-known/webfinger
to be redirected to
https://mastodon.alvani.me/.well-known/webfinger.

I used a CloudFlare redirect rule to accomplish this, as per the screenshot below.

*****
Written on