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.

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 stackoverflow.com Aug 18 '11 at 14:22

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

1 Answer 1

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.