2

How to obtain a directory name consisting of two last parts of the domain name. Or use a dot?

For example, I have a domain any.ms and I would like the dynamic domains foo.any.ms and domain bar.any.ms also pointing to the /var/www/dev/any.ms/public directory. Or domain any.lorem.ipsum.ms to point to the directory /var/www/dev/ipsum.ms/public.

My ms.conf for now (not working, apache won't start):

<VirtualHost *:80>
    ServerAlias *.ms
    VirtualDocumentRoot /var/www/dev/%-2%.%-1/public
    UseCanonicalName Off
    <Directory "/var/www/dev">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

I use the documentation http://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html but I can not insert dots writing /%-2.%-1/, /%-2%.%-1/, /%-2\.%-1/.

Gander
  • 1,854
  • 1
  • 23
  • 30

1 Answers1

3

I have just found a solution:

If you want to include the . (dot) character in a VirtualDocumentRoot directive, but it crashes with a % directive, you can work around the problem in the following way:

VirtualDocumentRoot /usr/local/apache/vhosts/%2.0.%3.0

Working solution:

<VirtualHost *:80>
    ServerAlias *.ms
    VirtualDocumentRoot /var/www/dev/%-2.0.%-1.0/public
    UseCanonicalName Off
    <Directory "/var/www/dev">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
Gander
  • 1,854
  • 1
  • 23
  • 30
  • 1
    Thanks for that, helped me too. But escaping the dot also works for me. E. g. `VirtualDocumentRoot "/var/www/dev/%1\.example.com"` – alpham8 Apr 17 '17 at 20:38