Force www to non-www on a subdomain in WordPress?

Forcing www to non-www is simple at the primary domain level.

It’s actually the same for the subdomain (depending on how you’ve written the directives in the first place). If the hostname (main domain or subdmomain) starts with www. then remove it.

(Forcing non-www to www for subdomains and main domains is a little more tricky if you want a generic single directive solution.)

The following removes the www subdomain from any hostname.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

In addition… If your subdomains are pointing to subdirectories off the main domain (eg. example.com/subdomain) then these subdirectories are probably also accessible and would need to be redirected. (Although search engines shouldn’t discover these subdirectories, or the www subdomain for that matter, unless it was leaked in some way.)