joshl_1995 22 Twisted Digital

Hello Community,
I'm trying to use dynamic subdomains which works but I'm only wanting .htaccess to to send subdomains without letters, numbers and underscores (_) to the 404 page. Here is my code.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

#Remove www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [QSA,NC,L]

#Example: http://example.com/directory/name
RewriteRule ^([a-z0-9_]+)$ http://example.com/directory/index.php?name=$1 [P,L]



#vv This Section vv
#Example: http://name.example.com
RewriteCond %{HTTP_HOST} ^([a-z0-9_]+).example.com [NC]
RewriteRule ([a-z0-9_]+) http://example.com/directory/index.php?name=%1 [P,L]
#^^ This Section ^^


#Remove .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

So if someone tries to use a subdomain that doesn't (only) contain letters, numbers and underscores (_) I would like them to be sent to the 404 page, but not so the 404 page is seen in the address bar like http://example.com/404.php but like http://name.example.com