Forum Moderators: phranque

Message Too Old, No Replies

Serving images from image directory outside of document root

Avoiding duplicate storage of identical files across sites

         

whoisgregg

3:06 pm on May 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello!

I have two sites on the same server: siteA and siteB. An image folder (huge, nested structure) inside the root of siteA is going to be duplicated into the identical relative location inside of siteB. I figured that instead of actually duplicating the image folder, I could internally rewrite requests for siteB images into siteA's image folder. Yet, it does not seem to be working.

This is what I am using in .htaccess in /www/hosts/siteB/images/project/

RewriteEngine On
RewriteBase /images/project/
RewriteRule ^(.+)$ /www/hosts/siteA/images/project/$1 [L]

When I try to access siteB.tld/images/project/sample.gif I get a 404 with the curious:

The requested URL /www/hosts/siteA/images/project/sample. gif was not found on this server.

Can I rewrite from inside one DocumentRoot into a different one? Is there a better way to accomplish this? Am I making any sense? :)

whoisgregg

4:40 pm on May 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I skipped the entire mod_rewrite approach and just put a symbolic link from one to the other.

In case anyone is curious, I accomplished that with:

ln -s /www/hosts/siteA/images/project /www/hosts/siteB/images/project 

jdMorgan

12:57 pm on May 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SymLinks are the way to go in these cases, because you cannot "cross over" from one document root to another with mod_rewrite. mod_rewrite will only work if bth the old and new URLs can be expressed as paths relative to the same documentroot.

The other -much less efficient- way to cross over is to proxy the destination directory through the server receiving the request (In this case, the destination serve actually has the image, and requests for that same image sent to the other server are passed through to it via a new HTTP request.)

Jim