Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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.