Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

If request is coming from http://xxx.domain.com,

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 httpd.apache.org/docs/1.3/vhosts/mass.html) I'm hoping maybe there is something for us as well. –  Devrim Nov 14 '09 at 1:20

3 Answers 3

I think what you are looking for is mass virtual hosting: http://httpd.apache.org/docs/1.3/vhosts/mass.html

Or http://httpd.apache.org/docs/1.3/mod/mod_vhost_alias.html

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 ...fail! 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>
ServerName xxx.example.com
DocumentRoot /www/xxx

<VirtualHost *:80>
ServerName yyy.example.com
DocumentRoot /www/yyy

above is a simple example of name-based...you can also use ip based:

<VirtualHost xxx.example.com>
ServerAdmin webmaster@example.com
DocumentRoot /groups/example/xxx
ServerName xxx.example.com
ErrorLog /groups/example_xxx/logs/error_log
TransferLog /groups/example_xxxx/logs/access_log

<VirtualHost yyy.example.com>
ServerAdmin webmaster@example.com
DocumentRoot /groups/example/yyy
ServerName yyy.example.com
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.