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

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 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/ Now when someone visits, it must load the test.gif from the .shared folder. Now when someone visits it must load the dog.png from the folder (because the existing apache rules will be executed first).

share|improve this question

You should use mod_rewrite module for apache2 and following rule. Following can be put in either virtual host configuation or in .htaccess file in DocumentRoot of your site.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (/.*)/([^/]+)
RewriteRule ^(.*)$ %1/.shared/%2

What this does essentially is check if file exists, if it does not then split your REQUEST_URI that looks like ...


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.

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.