How to create a Mastodon Alias on a different domain

As I want to have this account available under my "usual" handle already used for mail and jabber, I needed some kind of redirection. Other protocols have different methods to find out which server should be contacted to handle "@domainname.tld":

  • XMPP can use a DNS clue: _xmpp-server._tcp IN SRV 5269 jabber.kro.hn. tells the client to reach out to jabber@kro.hn on port 5269 to reach *@kro.hn accounts
  • SMTP also uses (an optional) DNS record

Mastodon and other fediverse-implentations use the "webfinger" URL to obtain details about an account:

GET /.well-known/webfinger?resource=acct:felix@kro.hn

To create a redirect to ${HERE} there are the following possibilities:

  • create static files under a /.well-known/ dir 
    • however, this is complicated because of special chars
    • they might or might not be urlencoded
    • also with uppercase and lowercase this creates too many permutations
  • install a handler to manage this 
  • redirect to the target domain using a HTTP 301 or 302 redirect
    • not tested, but probably more elegant (only found this after having achieved my goal): using Redirect instead of Rewrite
    • my solution:
      cat .well-known/.htaccess
      RewriteEngine On
      RewriteBase /.well-known/webfinger
      RewriteCond %{QUERY_STRING} ^resource=acct%3A@?[fF][eE][lL][iI][xX].* [OR]
      RewriteCond %{QUERY_STRING} ^resource=acct:@?[fF][eE][lL][iI][xX].*
      RewriteRule ^(.*)$ https://sozial.dezern.at/.well-known/webfinger?resource=acct:felix@sozial.dezern.at [R=301,L]
       
      (yes, funnily some requests arrive with an urlencoded colon (:), some without urlencoding)