0

So I have a virtual server set up for www.company.com:

<VirtualHost *:80>
    ServerName www.company.com
</VirtualHost>

And then I would like to direct *.company.com to another site. How do I do it? I could think of www. and inside. being directed at specific vhosts but "the rest" directed to a generic vhost.

Apache version is 2.2.4

drAlberT
  • 10,949
  • 7
  • 39
  • 52
Sandman
  • 349
  • 1
  • 4
  • 15
  • Although this may be useful locally, it is not best practice with regards to SEO and duplicate content http://www.wolf-howl.com/seo/wildcard-subdomains/ – Andy Sep 04 '09 at 10:33
  • It depends, obviously. I always set a "catchall" domain inserting the wildcard domain in the ServerAlias directive (yes, it is a quite different and more legal case ). The reason is I don't want that my customers could think I have something misconfigured on my servers, even if they have mistyped the url inserting a wrong subdomain name. – drAlberT Sep 04 '09 at 10:39

1 Answers1

8

The solution at your answer:

<VirtualHost *:80>
    ServerName www.company.com
    ServerAlias company.com
    DocumentRoot /path1
</VirtualHost>
<VirtualHost *:80>
    ServerName *.company.com
    DocumentRoot /path2
</VirtualHost>

The polite use of wildcards "catch all" domains:

<VirtualHost *:80>
    ServerName subdomain1.company.com
    DocumentRoot /path/to/subdomain1
</VirtualHost>

<VirtualHost *:80>
    ServerName subdomain2.company.com
    DocumentRoot /path/to/subdomain2
</VirtualHost>

<VirtualHost *:80>
    ServerName  company.com
    ServerAlias *.company.com
    DocumentRoot /path/to/primary/domain+catchall
</VirtualHost>

Note that the order is meaningful, the catchall domain has to be the last one. This is particularly useful to avoid a mistyping in the client url raises an "inexistent host" error, letting the customer of your company think you are a bad server admin (not him a bad typer :P).

drAlberT
  • 10,949
  • 7
  • 39
  • 52