There are already a bunch of rules in my Apache configuration. What I want to add is the following. There are some shared folders (.shared): /var/www/.shared/ and /var/www/.include/.shared/ and /var/www/.include/(.*)/.shared/. Now when someone visits http://domain.com/test.png it first executes the existing apache rules and will (when the file/folder was not found) look in those .shared folders.
So suppose I've got this filesystem: /var/www/.shared/dog.png /var/www/.shared/test.gif and /var/www/domain.com/dog.png. Now when someone visits http://domain.com/test.gif, it must load the test.gif from the .shared folder. Now when someone visits http://domain.com/dog.png it must load the dog.png from the domain.com folder (because the existing apache rules will be executed first).
You should use
mod_rewrite
module for apache2 and following rule. Following can be put in either virtual host configuation or in .htaccess file inDocumentRoot
of your site.What this does essentially is check if file exists, if it does not then split your
REQUEST_URI
that looks like .../directory/sub/directory/file.png
to 2 parts, first part is between two slashes '/' without second slash, and second one has file.png part .
/directory/sub/directory
file.png
This then allows you to insert '.shared' in path of new request where you want to send user to.