The following files show an example of how to create subdomains for onion site hidden services. (This hasn't been tested for hidden services for anything other than HTTP/HTTPS.)
(You might also want to read our blog post about ProPublica’s Tor hidden service, including a tutorial and notes on running a hidden service: https://www.propublica.org/nerds/item/a-more-secure-and-anonymous-propublica-using-tor-hidden-services )
In general, this works (maybe just in recent Tor clients) because Tor will handle
the connection to www.xxxxxxxxxxxxxxxx.onion
as a connection to
xxxxxxxxxxxxxxxx.onion.
The encapsulated HTTP/HTTPS connection contains the
subdomain in the Host:
header (and in the case of HTTPS, the SNI