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'm trying to follow on how to make subdomains that tails a specific directory, so for example I go to http://sub.mydomain.com and it should take me the root of /var/www/sub. http://randomdir.mydomain.com should take me to /var/www/randomdir.

I followed a lot of answers here on SF but none has helped at all. Basically what I have done is made a wildcard A record *.mydomain.com a couple days ago, now I've added a virtualhost in /etc/apache2/sites-enabled/mydomain.com.conf which contains this:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www/
</VirtualHost>

<VirtualHost *:80>
    ServerName cake.mydomain.com
    ServerAlias *.mydomain.com
    DocumentRoot /var/www/%1
</VirtualHost>

However, when restarting apache2, I get this returned:

Warning: DocumentRoot [/var/www/%1] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx for ServerName
 ... waiting Warning: DocumentRoot [/var/www/%1] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx for ServerName

How do I manage to create wildcard subdomains that point to a directory based on the prefix of the domain?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Change your DocumentRoot /var/www/%1 directive to VirtualDocumentRoot /var/www/%1.

share|improve this answer

This document, Dynamically Configured Mass Virtual Hosting seems to cover exactly what you are trying to do.

The areas covering the VirtualDocumentRoot directive are covered in more detail on the mod_vhost_alias documentation page and might be of particular interest to you.

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.