Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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/
  ServerName sumdomains.example.com
  ServerAlias *.example.com
  RewriteEngine On
  RewriteRule ^/(.*) /%{HTTP_HOST}/$1
</VirtualHost>

this means, a request to http://user.example.com/foo.html will fetch the file /var/www/user.example.com/foo.html.

but i want request to http://user.example.com/foo.html 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 1 down vote accepted

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

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

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

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

Your Answer

 
discard

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.