Not a thing to do with PHP or your htaccess.
If the browser is prepending www on front of a subdomain, than that is an issue with the user's browser. All you can do with it is remove the www from the provided input.
If you are using subdomains though, you should actually set them up. Your control panel should have an option to do so. If they are not real subdomains, I can see that being a bit flaky. You'll need to modify the DNS records to use wildcarded domains as well if they are not yet set.
header('HTTP/1.1 420 Enhance Your Calm');