Steven10172
Steven10172

Reputation: 2013

Allow sub domains, but don't match www

I'm currently trying to configure Apache vhost configuration and was hoping to be able to use mod_vhost_alias for everything.

Instead of setting up a configuration for each website I wanted to make it dynamic.

So far I have:

VirtualDocumentRoot /home/%-2.0.%-1.0/www

Which works fairly well, but I would like to be able to allow sub-domains so i tried the following:

VirtualDocumentRoot /home/%-2.0.%-1.0/www/%-3.0

But I don't want the DocumentRoot to be /home/example.com/www/www

Is there a way to achieve this? If not, would my best option to use mod_rewrite for subdomains?

Upvotes: 1

Views: 94

Answers (1)

Go0se
Go0se

Reputation: 98

You can add a ServerAlias before the VirtualDocumentRoot to catch the www. subdomain:

ServerAlias www.*
VirtualDocumentRoot /home/%-2.0.%-1.0/www

The top example would catch all www. subdomains.

To have the server behave as desired for all other subdomains, add another ServerAlias for all other subdomains like:

ServerAlias *
VirtualDocumentRoot /home/%-2.0.%-1.0/www/%-3.0

Hope this helps

Upvotes: 0

Related Questions