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:

<VirtualHost xxx.xxx.xxx.xxx:80>
        ServerName www.example.com
        ServerAlias *.example.com
...

That works perfect, except that it also enables subsubdomains. E.g.: www.test.server.com

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:

<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName www.example.com
    ServerAlias *.example.com

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

Your Answer

 
discard

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.