.htaccess subdomain redirect www to non-www

I searched a lot and tried previous answered questions but could not fix my problem. Imagine I have a subdomain named a.test.com I have the following .httaccess in its folder

DirectoryIndex disabled
RewriteEngine On

RewriteRule ^$ http://127.0.0.1:9000/ (P,L)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:9000/$1 (P,L)

This file is working and is redirecting all the requests from a.test.com to the localhost:9000 and everything is fine. But the problem is with www.a.test.com which does not work. I tried the following commands


RewriteCond %{HTTP_HOST} ^www. (NC)
RewriteRule ^ http://%1%{REQUEST_URI} (L,NE,R=301)

and

RewriteCond %{HTTP_HOST} ^www.a.test.com (NC)
RewriteRule ^(.*)$ http://a.test.com/$1 (L,R=301)

but none of them woks. I cannot debug the problem on the server to find out why those redirect rules does not work. I appreciate it if you help me with this issue.
thanks