Quantcast
Channel: Admins Goodies » subdomain
Viewing all articles
Browse latest Browse all 10

Automatic wildcard subdomains on Apache

$
0
0

Question

Currently I have several virtual hosts set up for individual subdomains. It would be a lot easier if I could tell Apache to automatically find the folder using a wildcard. For example, hello.domain.com would use the /var/www/hello directory as its DocumentRoot.

I would like to be able to define exceptions however, such as if I wanted helloworld.domain.com to point to /var/www/helloworld/public instead.

I’ve looked around but all of the examples seem to be doing something different.

Answer

You’ll be able to configure that behavior with something along these lines:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName catchall.domain.com
  ServerAlias *.domain.com
  VirtualDocumentRoot /var/www/%1
</VirtualHost>
<VirtualHost *:80>
  ServerName helloworld.domain.com
  DocumentRoot /var/www/helloworld/public
</VirtualHost>
Answered by Shane Madden

Viewing all articles
Browse latest Browse all 10

Trending Articles