To be more specific, you need to use a RewriteCond / RewriteRule instead of a simple Redirect directive. Make a negative match ( ! ) For foo.mydomain.com and rewrite. You can map multiple subdomains to the OR group (foo|other1|other2)
RewriteEngine On # Redirect anything except foo.example.com, bar.example.com RewriteCond %{HTTP_HOST} !^(foo|bar)\.example\.com$ [NC] # Redirect to www.example.com, preserving the URI RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=302]
If you just want to redirect to the root directory instead of adding the entire URI through $1 , use the same RewriteCond and just do:
source share