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

Configuring a local development linux box I'd like to have some sneaky Apache2 configuration which would do the following, when I request 'sub.domain.tld.local':

1.) Serve from: vhost/domain.tld/sub/htdocs/
2.) If there's no such directory, serve from: vhost/sub.domain.tld/htdocs/
3.) If there's no such directory, serve from: vhost/domain.tld/htdocs/

'.local' is just a static "suffix" which should not match any directory.

My current configuration looks like this:

<VirtualHost *:80>
    ServerAlias *.local
    UseCanonicalName Off
    VirtualDocumentRoot "/vagrant/host/%-2+/htdocs/"
    VirtualScriptAlias "/vagrant/host/%-2+/htdocs/"

This works well for 2) or 3) but not in the manner of "crawling" the directory structure and falling back from 1) to 2) to 3). Preferably I'd like to only use the VirtualDocumentRoot directive somehow without any rewrite rules.

If it won't work without rewrites, I'm of course okay with that too.

Any idea how to solve that?


locked by HopelessN00b Feb 18 '15 at 1:58

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

I could make this work with a few RewriteRule directives (I do something similar on my servers) but I don't know hiw it can be done with just VirtualDocumentRoot – Josh Mar 18 '13 at 13:56
Seems not doable with VirtualDocumentRoot alone, because it doesn't check existence of directories. What helps a little, and what I find quite interesting, is the fact, that ServerAlias works with multiple wildcards - like: "ServerAlias *.*.*.com" for example. :) – Thasmo Mar 19 '13 at 23:21

Browse other questions tagged or ask your own question.