Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Last active April 6, 2025 02:26
Show Gist options
  • Save aaronpk/5846789 to your computer and use it in GitHub Desktop.
Save aaronpk/5846789 to your computer and use it in GitHub Desktop.
Added WebFinger support to my email address using one rewrite rule and one static file.
[aaron@parecki.com www]$ cat .htaccess
RewriteEngine on
RewriteCond %{QUERY_STRING} resource=acct:(.+)
RewriteRule ^\.well-known/webfinger /profile/%1? [L]
[aaron@parecki.com www]$ cat profile/aaron@parecki.com
{
"subject": "acct:aaron@parecki.com",
"links": [
{
"rel": "http://webfinger.net/rel/avatar",
"href": "http://aaronparecki.com/images/aaronpk.png"
},
{
"rel": "http://webfinger.net/rel/profile-page",
"href": "http://aaronparecki.com/"
},
{
"rel": "me",
"href": "http://aaronparecki.com/"
}
]
}
@steelman
Copy link

steelman commented Nov 19, 2024

Alas according to the documentation RewriteMap cannot be declared in a per-directory context including .htaccess. So one probably need to name their json files with %40 instead of @ or symlink them because some clients (e.g. Mastodon) send unescaped requests. This also requires to support both : and %3a

RewriteCond %{QUERY_STRING} resource=acct(:|%3[Aa])([^&]+)
RewriteRule ^\.well-known/webfinger /webfinger/%2? [NE,T=application/jrd+json;charset=UTF-8]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment