Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

i use this config in apache2 for wildcard subdomain and works good :

<VirtualHost *:80>
  DocumentRoot /var/www/
  ServerAlias *
  RewriteEngine On
  RewriteRule ^/(.*) /%{HTTP_HOST}/$1

this means, a request to will fetch the file /var/www/

but i want request to fetch file from /var/www/user/foo.html.

which wildcard should am i use for this?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Set rewrite rule grab the sub.domain and redirect to /sub/requestedFile

RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9-]+)\$
RewriteRule ^(.+) /%1/$1 [L,QSA]

Or set VirtualDocumentRoot with %-1 representing the sub domain.

<VirtualHost *:80>
  VirtualDocumentRoot /var/www/%-1
  ServerAlias *
share|improve this answer
works like a charm! thanks :) – Amir Molaa Apr 13 '13 at 12:28

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.