Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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).

share|improve this question
add comment

1 Answer

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 ...

/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.

share|improve this answer
add comment

Your Answer

 
discard

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.