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'm trying to setup zero-config web-development environment: wildcard DNS plus dynamic virtual hosts. Here is my v-hosts config:

NameVirtualHost *:80

<VirtualHost *:80>
ServerAlias *.dev               
    VirtualDocumentRoot /var/sites/%-2/docs
    UseCanonicalName Off
</VirtualHost>

At this point everything is ok, but now I'm trying to setup dymanic subdomains with fallback:

test.dev           → /var/sites/test/docs
sub.test.dev       → /var/sites/test/sub
dontexist.test.dev → /var/sites/test/docs

Directory structure:

var
|--sites
   |--test
      |--docs
      |--sub

What i currently try:

<Directory "/var/sites">
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_SUBDOMAIN} ="" 
    RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.([a-z0-9][-a-z0-9]+)\.dev\.?(:80)?$ [NC] 
    RewriteCond %{DOCUMENT_ROOT}/%2/%1 -d 
    RewriteRule ^(.*) /%2/%1/$1 [E=SUBDOMAIN:%1,L]
</Directory>

And now stacked at:

[perdir /var/sites/] strip per-dir prefix: /var/sites/test/docs/ -> test/docs/
[perdir /var/sites/] applying pattern '^(.*)' to uri 'test/docs/'
[perdir /var/sites/] RewriteCond: input='' pattern='=' => matched
[perdir /var/sites/] RewriteCond: input='sub.test.dev' pattern='^([a-z0-9][-a-z0-9]+)\.([a-z0-9][-a-z0-9]+)\.dev\.?(:80)?$' [NC] => matched
[perdir /var/sites/] RewriteCond: input='/var/sites/test/sub' pattern='-d' => matched
[perdir /var/sites/] rewrite 'test/docs/' -> '/test/sub/test/docs/'
setting env variable 'SUBDOMAIN' to 'sub'
[perdir /var/sites/] internal redirect with /test/sub/test/docs/ [INTERNAL REDIRECT]
[perdir /var/sites/] add path info postfix: /var/sites/test/docs/test -> /var/sites/test/docs/test/sub/test/docs/
[perdir /var/sites/] strip per-dir prefix: /var/sites/test/docs/test/sub/test/docs/ -> test/docs/test/sub/test/docs/
[perdir /var/sites/] applying pattern '^(.*)' to uri 'test/docs/test/sub/test/docs/'
[perdir /var/sites/] RewriteCond: input='sub' pattern='=' => not-matched
[perdir /var/sites/] pass through /var/sites/test/docs/test

Any ideas?

Is that even possible?

Thanks

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.