Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have subdomains coinfigured with apache via the wildcard:

        ServerAlias *

That works perfect, except that it also enables subsubdomains. E.g.:

How can I make sure only subdomains are valid and subsubdomains not?

share|improve this question
rewrite rules for subsub? – Lazy Badger Oct 18 '11 at 13:21

AFAIK, ServerAlias only support wildcard, not regex. You should do it with mod_rewrite, something like this:

    ServerAlias *

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(?:[^.]+)\.example\.com [NC]
    RewriteRule ^(.*)$$1 [R=301,L,QSA]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.