0

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

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .