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

I'd like to redirect all subdomains *.local to their sub dirs, for example:

test.local/ --> /files/test/data/

Here's my vhost file:

<VirtualHost *:80>
    ServerName local
    ServerAlias *.local
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.* [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.local
    RewriteCond /files/%1/data -d
    RewriteRule ^(.*) /mv/$1/data

The trouble is that's not working, I get a file not found error.

Any ideas?

share|improve this question

migrated from Aug 18 '11 at 14:22

This question came from our site for professional and enthusiast programmers.

While you've got more going on there in the mod_rewrite setup than just this, VirtualDocumentRoot may fill your needs?

<VirtualHost *:80>
    ServerName local
    ServerAlias *.local
    VirtualDocumentRoot /files/%-2/data

(the %-2 specifies that the second to last name in the domain should be used; so for www.test.local and for test.local, /files/test/data will be used in both cases)

share|improve this answer

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.