There's an response to the question of handling wild card subdomains, but it doesn't meet my needs. I have to do many of these, assuming for instance the domain is example.com:

  1. When the domain given is world wide web.example.com it will 301 redirect to example.com because I don't want to possess duplicate content and build problems in search engines like google.

  2. When the domain is anythingelse.example.com it will quietly redirect to example.com to ensure that software can select up what subdomain was asked for and act accordingly.

  3. Additionally, any specs following the domain title that doesn't make reference to a real file or directory ought to be rerouted to index.php (again the program will evaluate which everything meant). So anything.example.com/some/search/engine/friendly/specs should redirect to example.com/index.php.

I'm able to get areas of this to operate, but haven't yet attain the whole factor. Any offers!

Try these rules:

# 1. rule
RewriteCond %{HTTP_HOST} =www.example.com
RewriteCond %{HTTPS} ^on(s)|
RewriteRule ^ http%1://example.com%{REQUEST_URI} [L,R=301]

# 2. rule
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ /absolute/filesystem/path/to/example.com%{REQUEST_FILENAME} [L]

# 3. rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]