Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If request is coming from,

i want to be able to say;

DocumentRoot /home/${SUBDOMAIN_NAME}

so that Virtual host's DocumentRoot will be assigned to /home/xxx

Any way I can accomplish this?

Thanks, D

ps: please don't worry about security or how bad this idea is. I have over-simplified the problem for the sake of simplicity.

Real usage will be as follows:

<IfModule mpm_itk_module> AssignUserId ${SUBDOMAIN_NAME} usergroup </IfModule>

There will be a unix user with the corresponding subdomain name.

share|improve this question
I will also accept "no you can't" as an answer if you don't mind explaining why. – Devrim Nov 13 '09 at 22:25
I know all these variables are set at the time when apache reloads ( so there is no request coming in at the time of restart), but sometimes there are workarounds (such as I'm hoping maybe there is something for us as well. – Devrim Nov 14 '09 at 1:20

I think what you are looking for is mass virtual hosting:


You probably want something like:

UseCanonicalName    Off
VirtualDocumentRoot /home/%-1

%-1 would get the subdomain.

Read the sites listed for more information.

share|improve this answer
Hi Nathan, I thought this would work great but here is what i get: apache2: bad user name %-1! I'm using it inside: <IfModule mpm_itk_module> AssignUserId %-1 usergroup </IfModule> – Devrim Nov 14 '09 at 6:42
${%-1} didn't work either. – Devrim Nov 14 '09 at 6:45
The % syntax only works with VirtualDocumentRoot. You won't be able to plug % into any other parameter. – Nathan Adams Nov 14 '09 at 15:13
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/xxx

<VirtualHost *:80>
DocumentRoot /www/yyy

above is a simple example of can also use ip based:

DocumentRoot /groups/example/xxx
ErrorLog /groups/example_xxx/logs/error_log
TransferLog /groups/example_xxxx/logs/access_log

DocumentRoot /groups/example/yyy
ErrorLog /groups/example_yyy/logs/error_log
TransferLog /groups/example_yyy/logs/access_log
share|improve this answer
this isn't an answer to what i asked. thanks though. – Devrim Nov 13 '09 at 22:20
sorry...i must've misunderstood the question. – user6373 Nov 13 '09 at 23:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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