1

I'm using a VirtualDocumentRoot setting on my dev system, so I can easily work on multiple projects without updating the VirtualHosts all over the time.

That currently looks like that:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    VirtualDocumentRoot /var/www/%1
    ServerName everything.localhost
    ServerAlias *.localhost
</VirtualHost>

So I can access the directories below /var/www e.g. by calling foobar.localhost.

The problem is that I now also have projects which are working with a different document root directory, e.g. have another src, pub or public folder in the repository so I want to use these, but that differs per project. So the idea was to extend the VirtualDocumentRoot with another level:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    VirtualDocumentRoot /var/www/%1/%2
    ServerName sub.everything.localhost
    ServerAlias *.*.localhost
</VirtualHost>

So I can call these project e.g. with src.foobar.localhost. Unfortunately that conflicts with the previous rule so I can no longer access the "old" projects which don't have an extra subdirectory.

Is there a way of dealing with both of these VirtualHosts/VirtualDocumentRoots in one apache configuration?

An idea I already had was to have another base domain, like localhost2 for the subdirectories, so the ServerAlias would only match that rule, but that's not the preferred solution.

2
  • How do those vhosts conflict? Does one hide the other? Does switching the order help? Jun 19 '14 at 12:32
  • It always uses the VirtualHost with ServerAlias *.localhost. So the extra . in the domain seems also to be matched by the asterisk. Switching the order doesn't help :(
    – Tobias
    Jun 20 '14 at 7:16
1

what about symlink the actual root directory into the original vhost dir?

ln -sTv /var/www/fullrepo-project.localhost/pub /var/www/project.localhost
1
  • Nice idea, thanks. That's definitely an option, but I'll leave the question open, maybe someone can really fix the conflict in the apache config
    – Tobias
    Jun 20 '14 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.