Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Given a URL:

The document root for is /var/www/

I want apache to:

1) If /var/www/ exists, serve it.
2) If /var/www/ doesn't exist, 
   check /var/www/shared/
3) If /var/www/shared/ doesn't exist, send a 404

Is this possible?

I've looked in to the Alias directive, but I think this will require me to have something in the URI indicating where the resource is.

share|improve this question
This would be pretty trivial with nginx's try_files. Ever considered switching? – Michael Hampton Jun 2 '13 at 20:50
Thanks Michael, you just convinced me to switch. Do you have any links regarding the triviality of a setup like this? – jessh Jun 3 '13 at 0:06
up vote 2 down vote accepted

For files outside the DocumentRoot, check out the aptly named documentation section on "Files Outside the DocumentRoot" -- you're looking at creating an Alias, and you may be able to do it without a redirect.

share|improve this answer
I think this is on the right track.. but it will require me to have some indicator of the resource in the URI.. e.g. I can't just alias "/" – jessh Jun 3 '13 at 0:34
RewriteCond %{DOCUMENT_ROOT}$1 !-f
RewriteRule (.*) /var/www/shared$1 [last]
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.