If possible, you should define a "Wild-card" DNS record for your domain, so that *all* possible subdomains will resolve to your server. Typically, it would look something like:
*.example.com. 86400 IN A 192.168.0.1
Note the trailing period on the domain name.
Having done that, add a 301-Redirect to redirect requests for all resources at all non-canonical hostnames to the same resources at the canonical hostname.
If you have a unique IP address for your server (whether it's on shared hosting or not), then you should be able to do all of this yourself. If you share an IP address with other sites hosted on the same server, then you may have to ask your host for help in order to get wild-card subdomains working.