It's niche problem, but for organizations hosting lots of sites it can be important to know when a site's hostname should have www
in front of it. The daemon bases this decision on the number of DNS labels that exist when the TLD is removed from the hostname. Uses data from Mozilla's Public Suffix List initiative.
RewriteLock /tmp/rewrite.lock
RewriteMap wwwify prg:/usr/local/bin/wwwify -t /etc/tlds.dat -T -s /tmp/wwwify.stats
RewriteCond ${wwwify:%{HTTP_HOST}|%{HTTP_HOST}} ^(www\.[a-z0-9_.-]+)$ [NC]
RewriteCond %1 ^((?!%{HTTP_HOST}))$ [NC]
RewriteRule ^(.*) %{ENV:X_REQ_PROTOCOL}://%1$1 [R=permanent,L]