Using your own domain in your lightning payment address

A lightning address is a good way to pay someone with Bitcoin; it’s also a way to receive streaming payments for your podcast.
My lightning address is currently jamescridland@strike.me, but what happens if I decide to change? Maybe I’ll go to Alby, or to the ZBD app. What a hassle to have to tell everyone that I’ve changed. And everyone who forgets to change… well, I won’t get that money any more.
Lightning looks like an email address (which is probably a mistake, but let’s let that slide) - and you ought to own your own domain really.
The good news is that an lnaddress is a lookup on a webserver, where a payment system can find the real details to send it.
When you try to send me money to jamescridland@strike.me your payment system first calls https://strike.me/.well-known/lnurlp/jamescridland which contains a small amount of JSON telling the system where to make a payment.
So, if I wanted james@podnews.net to be the address I publish, I just need to sort out a similar lookup at https://podnews.net/.well-known/lnurlp/james.
If you’re running PHP, then you need one line in your .htaccess file to handle the incoming request; and then a simple proxy of the data. Here’s how I do it…
<?php
header ("Access-Control-Allow-Origin: *");
header ("Content-Type: application/json; charset=utf-8");
//
// The .htaccess line is:
// RewriteRule ^.well-known/lnurlp/(.*)$ /_pages/wellknown-lnurlp.php?user=$1 [QSA]
//
// This results in
// https://podnews.net/.well-known/lnurlp/sam
//
// Caching is a good idea for this
//
$url["sam"]="https://getalby.com/.well-known/lnurlp/truefans";
$url["james"]="https://strike.me/.well-known/lnurlp/jamescridland";
if(isset($url[$_REQUEST["user"]])) {
echo file_get_contents($url[$_REQUEST["user"]]);
} else {
http_response_code(404);
}
So now, you can send sats to james@podnews.net or sam@podnews.net and it’ll work nicely behind the scenes: and I can change the actual places it goes to very easily. Much like email.