Aug 9, 2011
tom

Apache vhosts 2 domains

Question

com and .co.uk domains, is it possible to create a virtual host to point to a single directory on the box?

At present I have

<VirtualHost *:80>
    ServerName www.domain.co.uk
    ServerAlias domain.co.uk
    DocumentRoot "C:/htdocs/domain.com/htdocs"    <Directory />
    Options +Includes
    </Directory>    ErrorLog  "C:/htdocs/domain.co.uk/logs/error.log"
    CustomLog "C:/htdocs/domain.co.uk/logs/access.log" combined

Answer

Yes just add them to your ServerAlias

ServerAlias domain.co.uk www.domain.com domain.com

Or you could do it like this:

ServerName domain.co.uk
ServerAlias *.domain.co.uk domain.com *.domain.com

I think you have som inconsistency problems with your posted code. Using both C:/htdocs/domain.co.uk/ and C:/htdocs/domain.com/

If it was up to me. I would put everything in C:/htdocs/domain.com/ and use the following

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *.domain.com domain.co.uk *.domain.co.uk
    DocumentRoot "C:/htdocs/domain.com/htdocs"    <Directory />
        Options +Includes
    </Directory>    ErrorLog  "C:/htdocs/domain.com/logs/error.log"
    CustomLog "C:/htdocs/domain.com/logs/access.log" combined
</VirtualHost>

Please note, when using *.domain.com (star-alias) in ServerAlias. If you wish to add a specific subdomain (example delicious-subs.domain.co.uk) in a new VirtualHost – pointing to another location. Then you will have to add that new VirtualHost with above/before the VirtualHost using the star-alias.

Related posts:

  1. Apache VHost Configuration Precedence?
  2. Managing domains on centos
  3. Wild card sub-domain routing in Apache
  4. redirect to the respective virtual host a wrong third level domain
  5. Apache rewrite multiple conditions

Leave a comment