Quantcast
Viewing latest article 10
Browse Latest Browse All 10

Automatic wildcard subdomains on Apache

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
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 latest article 10
Browse Latest Browse All 10

Trending Articles