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 want to offer custom subdomains for my customers. I can add virtual host configuration for each subdomain but it gets a overwhelming job as the number of users increase.

What I currently use is like this:

NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot /var/www/mysite/user1
  ServerName user1.mysite.com
</VirtualHost>
<VirtualHost *:80>
  DocumentRoot /var/www/mysite/user2
  ServerName user2.mysite.com
</VirtualHost>
<VirtualHost *:80>
  DocumentRoot /var/www/mysite
  ServerName example.com
  ServerAlias www.mysite.com
</VirtualHost>

Is there a better way of configuring subdomains?

Is it possible to make a simple check and direct an non-existing virtual host to the main site?

PS: Some other Virtualhosts still need to be defined this way.

share|improve this question

1 Answer 1

YES THERE IS.

Within your VirtualHost definition:

VirtualDocumentRoot /var/www/multipledomains_root/%0

Then anything that comes at the HTTP_HOST header apache will try to match in %0

Look at (http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html) to have a complete list of what you can do.

share|improve this answer
    
does it work along with regular VirtualHost configuration –  mustafa Mar 27 '13 at 18:05
    
yes, and you should if you have multiple rules for subdomain hosting. –  Marcel Mar 27 '13 at 18:19

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.