5

Given a URL:

http://example.com/some-file.zip

The document root for example.com is /var/www/example.com/

I want apache to:

  1. If /var/www/example.com/some-file.zip exists, serve it.
  2. If /var/www/example.com/some-file.zip doesn't exist, check /var/www/shared/some-file.zip
  3. If /var/www/shared/some-file.zip 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.

Giacomo1968
  • 3,542
  • 27
  • 38
jshawl
  • 297
  • 2
  • 13

2 Answers2

6

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.

KM.
  • 1,786
  • 2
  • 18
  • 31
  • 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 "/" – jshawl Jun 03 '13 at 00:34
3
RewriteCond %{DOCUMENT_ROOT}$1 !-f
RewriteRule (.*) /var/www/shared$1 [last]
200_success
  • 4,771
  • 1
  • 25
  • 42
  • 2
    core:error "The given path was above the root path" – tim Jun 16 '20 at 00:32
  • 2
    This directive is to be used in a _server_ or _virtualhost_ context, not `.htaccess` (or other _directory_ context). However, you'll still need to grant access to `/var/www/shared` in the server config, if not already. @tim – MrWhite Dec 12 '20 at 01:01
  • this works only for apache – gdm Jan 21 '21 at 16:25