7

I have the following in my Apache config:

<VirtualHost *:80>
  VirtualDocumentRoot /var/www/hosts/%0
  ServerAlias *.test.galapagos.office
</VirtualHost>

In /var/www/hosts, I have a directory called jason.test.galapagos.office and one called bill.test.galapagos.office. If I go to jason.test.galapagos.office in a browser, I get what I expect to see. Same with bill. In other words, everything is working perfectly.

However, I'm not quite satisfied with what's going on. Instead of /var/www/hosts/jason.test.galapagos.office and /var/www/hosts/bill.test.galapagos.office/, I'd like /home/jason/web and /home/bill/web.

How can I tell Apache to map to those subdirectories instead?

Thanks, Jason

Jason Swett
  • 1,458
  • 4
  • 23
  • 37

2 Answers2

16

Try this:

<VirtualHost *:80>
  #VirtualDocumentRoot /var/www/hosts/%0
  VirtualDocumentRoot /home/%1/web
  ServerAlias *.test.galapagos.office
</VirtualHost>

I believe that will sent requests to "jason.test.galapagos.office" to "/home/jason/web"

The full list of VirtualDocumentRoot directives can be found here:

http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

0     the whole name
1     the first part
2     the second part
-1    the last part
-2    the penultimate part
2+    the second and all subsequent parts
-2+   the penultimate and all preceding parts
1+ and -1+     the same as 0
sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
1

Could this change work?

VirtualDocumentRoot /home/%0/web

Or you may consider enabling mod_userdir, that by default would look like http://test.galapagos.office/~bill/

LatinSuD
  • 841
  • 1
  • 8
  • 15
  • That wouldn't quite get me what I want. With that solution, my directories would still have to look like this: /home/jason.test.galapagos.office/web instead of like this: /home/jason/web. – Jason Swett Sep 20 '10 at 18:15